I'm trying to use a reactive array in a component. It works with an object but not with an array of objects.
How can I update the view when the array is updated?
var self = currentClassInstance // this
self.store = {
resources: Vue.reactive([]),
test: Vue.reactive({ test: 'my super test' }),
setResources(resources) {
// this one doesn't update the view. ?
this.resources = resources
},
setResources(resources) {
// this one update the view
this.test.test = "test ok"
},
}
....
const app_draw = {
data() {
return {
resources: self.store.resources,
test: self.store.test,
}
},
updated() {
// triggered for "test" but not for "resources"
console.log('updated')
},
template: '<div v-for="(resource, key) in resources" :data-key="key">{{resource.name}}</div>'
};
....
According to the official docs :
i suggest to assign the array to field called value inside the reactive parameter like you did with
test
:then use
resources.value=someVal
to update that value.