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.
Answered by
posva
Nov 10, 2021
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.
1 reply
Answer selected by
amrap030
-
You can use the this.$set function: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.*
)