-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Computed properties calculation results are inconsistent #1162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Note the fix for this will be reverted in 1.0.0. The reason is that
|
Although the top two examples has the same result: 1------new data, I modified the example: It will spend more time than before ( sync: true) How to reduce the performance problem caused by the computed properties re-evaluated in this case? Vue.config.debug =true;
vue = new Vue({
el: '#demo',
data: {
content: 'old data'
},
methods:{
readContent: function(){
var self = this;
setTimeout(function(){
self.$.test.index = 1;
self.content = 'new data';
},2000);
}
},
components: {
'test-content': {
props:['content'],
data: function(){
return {
index: 0
}
},
computed: {
detailContent: function(){
//more waste of time
/***************************/
var start = +new Date();
var end = start + 3000; // +3s
while(start < end){
start = +new Date();
}
var tmp = this.index + '------' + this.content;
console.log(tmp);
return tmp;
}
}
}
}
}) |
It's only a performance problem if it actually slows down your app. Simple computed properties are very fast to evaluate and the extra calls are an ok tradeoff to ensure correctness of the while system. If you have a real case where this behavior is the cause of a noticeable performance issue, then we'll consider fixing it. |
Different code sequence have different computed result
_we want the result is example 1_
example 1 , console.log results:
0------old data
1------new data
example 2 , console.log results:
0------old data
1------old data
1------new data
Example 1: the results we want
example 2:
The text was updated successfully, but these errors were encountered: