Reputation: 27
When on click start method "increment" variable "clicks" change but why it not change "counter". It should be because i have in counter function reference to "clicks" variable.
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;
}
}
});
https://jsfiddle.net/freeq343/b7fyeyxm/
Upvotes: 1
Views: 74
Reputation: 82439
Don't define counter on your data. The computed value acts like a data property.
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;
}
}
});
Upvotes: 1