Cannot assign because it is a read-only property #787
-
Hello, for some reason I get the following error when assigning a value to My code looks like this, what am I doing wrong? import { defineStore } from "pinia";
import { getBalance } from "@/services/wallet-service";
export const useUserStore = defineStore("main", {
// initial state
state: () => ({
address: "",
balance: 0,
}),
getters: {
address: (state) => state.address,
balance: (state) => state.balance,
},
actions: {
async initBalance() {
try {
this.balance = await getBalance();
} catch (e) {
console.log(e);
this.balance = 0;
}
},
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
remove the getters, you don't need them Also worth noting that state, getters, and actions names cannot overlap as they are all merged into the store instance ( |
Beta Was this translation helpful? Give feedback.
-
You can use the this.$set function: |
Beta Was this translation helpful? Give feedback.
remove the getters, you don't need them
Also worth noting that state, getters, and actions names cannot overlap as they are all merged into the store instance (
this.*
)