計算屬性(computed)
index.html
<div>Reverse Title: {{reverseTitle}}</div>
index.js
Vue({
  data: {
      title: 'Test'
  },
  computed: {
    // 自定義屬性
        reverseTitle: function () {
            return this.title.split('').reverse().join('')
        }
  }
})
計算屬性 v.s. 方法
  methods: {
        reverseTitle: function () {
            return this.title.split('').reverse().join('')
        }
  }
和
computed: {
    // 自定義屬性
        reverseTitle: function () {
            return this.title.split('').reverse().join('')
        }
  }
data: {
    firstName: 'Shawn',
    lastName: 'Tseng'
},
computed: {
        fullName: {
            get: function () {
                return this.firstName + ' ' + this.lastName
            },
            set: function (newValue) {
                var name = newValue.split(' ');
                this.firstName = name[0];
                this.lastName = name[name.length - 1];
            }
        }
}
  data: {
    age: '',
    reply: '',
  },
  watch: {
      age: function (oldValue) {
        this.reply = '你的年紀:' + oldValue;
      }
  }
- 在age變動時,會執行watch的邏輯,非常消耗資源
- 在需要串接後端的情境常使用
