I have a watch
property that watches some options
passed to the data
function.
Every time an option changes the watch handler gets triggered as I expect. Now, I would also like to fire the handler whenever I dynamically change the DOM structure.
At the moment I was using an ugly hack to force the handler to get fired. I was setting an option again with an &
:
this.options.navigation = this.options.navigation & true;
Is there some way I can manually call the watch handler? Something like:
this.fireWatch();
My vue file:
export default {
props: {
options: {
type: Object,
default: () => {
return {};
},
},
},
watch: {
options: {
deep: true,
handler() {
this.init();
},
},
},
mounted() {
this.init();
},
methods: {
init() {
$(this.$el).myPlugin({
...this.options,
...this.events,
});
},
emitEvent(name, args) {
// Emit event on Vue way
this.$emit.apply(this, [camelToKebab(name), ...args]);
// Run event's handler with non Vue way
if (this.options.hasOwnProperty(name)) {
this.options[name].apply(this, args);
}
},
}
}