[Vuejs]-Clear data object on route change

0๐Ÿ‘

1.user a global event bus in the entry js

window.eventBus = new Vue();

2.add a event handler to this color picker component , ie in ready()

ready(){   
    var vm = this  
    eventBus.$on('clearColorPicker', function(){vm.color = ''})
}

3.trigger the clearColorPicker event in $route.afterEach by

eventBus.$emit('clearColorPicker')

This can help you to trigger some change to certain component during route change.

But I think In your case there is a better way like the changing of product trigger the color picker reset

๐Ÿ‘คamow

Leave a comment