+
95
-

vue中computed 和 watch 有什么区别?

vue

vue中computed 和 watch 有什么区别?


网友回复

+
15
-

1.watch是监听器,监听一个data中值的改变,例如下面通过watch监听来实现实现全名计算。

var var vm = new Vue({
  el: '#demo',
  data: {
    firstName: 'Foo',
    lastName: 'Bar',
    fullName: 'Foo Bar'
  },
  watch: {
    firstName: function (val) {
      this.fullName...

点击查看剩余70%

我知道答案,我要回答