[Vuejs]-Code attached to watch: {} never executes although the watched variable does indeed change

1👍

You have to do something like this:

new Vue({
  el: '#app',
  data() {
    return {
        form: {
            ac_all: false
        }
    }
  },
  watch: {
    'form.ac_all'() {
        console.log('form.ac_all value is ' + this.form.ac_all)
    }
  }

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <button @click="form.ac_all = !form.ac_all">Toggle</button>
</div>

Leave a comment