[Vuejs]-How to manually stop a watcher?

4👍

The "watch" function returns a function which stops the watcher when it is called :

const unwatch = watch(someProperty, () => { });

unwatch(); // It will stop watching

To watch a change only once:

const unwatch = watch(someProperty, () => {
   // Do what your have to do

   unwatch();
});

Leave a comment