Vue: Test Reactive

When are they reactive?

by mattoconnell408

HTML

<script src="https://rawgit.com/yyx990803/vue/master/dist/vue.js"></script>
<div id="app">
  <p>{{a}}</p>
</div>

Babel + JSX

const vm = new Vue({
  el: '#app',
  data(){
    return {
      a: 0
    };
  }
});

vm.$watch('a', function (newVal, oldVal) {
	// this will have the updated DOM value
  console.log('from watch', vm.$el.textContent)
})

setTimeout(() => {
  vm.a += 1; 
  // this will not
  console.log('immediately after', vm.$el.textContent)
}, 1000);