[repeat] how to set ref value type safely #1259
Answered
by
posva
kagaricyan
asked this question in
Help and Questions
-
here is my code: I just want to change the list item state independently import { Ref, ref } from '@vue/composition-api';
export const useStore = defineStore('store', {
state: (): State => ({
list: [],
state: {},
}),
actions: {
initState() {
this.list.forEach(item => {
// TS2322: Type 'Ref ' is not assignable to type 'boolean'.
this.state[item.p] = ref(false);
});
},
changeState(res: string) {
this.state[res] = true; // ? or this.state[res].value = true;
},
},
getters: {
getList(state) {
return state.list.map(item => ({
p: item.p,
state: state.state[item.p],
}));
},
},
}); |
Beta Was this translation helpful? Give feedback.
Answered by
posva
May 2, 2022
Replies: 1 comment
-
Just do // Vue 3
this.state[item.p] = false
// Vue 2
Vue.set(this.state, item.p, false) You don't need to create refs there |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kagaricyan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just do
You don't need to create refs there