Answer the question
In order to leave comments, you need to log in
How to make an instance property in VUE reactive?
In the plugin, I declare the prototype property: Vue.prototype.$dataGroups = [];
But as it turned out, it is not reactive.
Setting the property with Vue.set didn't work either:
Vue.set(Vue.prototype, '$dataGroups', ["navigation"]);
Answer the question
In order to leave comments, you need to log in
Hmm, something like this comes to mind:
const box = new Vue({data: {groups: []}});
Object.defineProperty(Vue.prototype, '$dataGroups', {
configurable: true,
get() { return box.groups; },
set(value) { box.groups = value; }
});
Vue.mixin({
beforeCreate() {
const {$options} = this;
const {parent} = $options;
if($options.dataGroups) {
const groups = typeof $options.dataGroups === 'function' ? $options.dataGroups() : $options.dataGroups;
const box = new Vue({data: {groups}});
Object.defineProperty(this, '$dataGroups', {
configurable: true,
get() { return box.groups; },
set(value) { box.groups = value; }
});
return;
}
if(!parent) { return; }
const descriptor = Object.getOwnPropertyDescriptor(parent, '$dataGroups');
if(!descriptor) { return; }
Object.defineProperty(this, '$dataGroups', descriptor);
}
});
If you want something simple, then you can use a simple state container and use the event bus for the actor component model
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question