Vuejs2 Vue 2.0-计算问题

Vuejs2 Vue 2.0-计算问题,vuejs2,Vuejs2,单击开始方法“增量”变量时,单击“更改,但为什么不更改”计数器。这应该是因为我在计数器函数中引用了“clicks”变量 new Vue({ el: '#app', data: { title: 'helloworld', cssClass: '', clicks: 0, counter: 0 }, methods: { changeTitle() { this.title = 'helloworld new';

单击开始方法“增量”变量时,单击“更改,但为什么不更改”计数器。这应该是因为我在计数器函数中引用了“clicks”变量

new Vue({
    el: '#app',
  data: {
    title: 'helloworld',
    cssClass: '',
    clicks: 0,
    counter: 0
  },
  methods: {
    changeTitle() {
        this.title = 'helloworld new';
    },
    increment() {
        this.clicks++;
    }
  },
  computed: {
    counter() {
        return this.clicks * 2;
    }
  }
});

不要在数据上定义计数器。计算值的作用类似于数据属性

new Vue({
    el: '#app',
  data: {
    title: 'helloworld',
    cssClass: '',
    clicks: 0
  },
  methods: {
    changeTitle() {
        this.title = 'helloworld new';
    },
    increment() {
        this.clicks++;
    }
  },
  computed: {
    counter() {
        return this.clicks * 2;
    }
  }
});