Vue 2.0 Issue

Watch options immediate has no effect

by ChangJoo Park

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/vue"></script>

<div id="app">
  <button @click="updateMessage">Update</button>
  <p>{{ message }}</p>
  <p>Handler from watch component options called {{ componentCount }} times</p>
  <p>Handler from $watch method options called {{ methodCount }} times</p>
</div>

JavaScript

new Vue({
  el: '#app',
  data: {
    message: 'Hello Vue.js!',
    componentCount: 0,
    methodCount: 0
  },
  created: function() {
  	console.log('created')
  },
  watch: {
    message: {
      immediate: true,
      handler: function () {
        console.log('변경됨')
        this.componentCount++
      }
    }
  },
  methods: {
    updateMessage () {
      this.message = "Hello Vue.js! (Changed)"
    } 
  }
})