What is the differences between data and computed?

.

the two code snippets above,they will have a totally same result
so,what is the difference between data and computed?
and,someone told me,hey,why don’t you consult the documentation for answer?
is there really an answer in the documentation for this question?

okay,let me answer these questions for you,if you can endure my poor english.
after thinking about this for a long time,i think i’ve got a little from this and want to share with you.
q1:what are the differences between data and computed? as if they just give the same functionality in the framework.
a:yes,in some cases they give the same functionality.but if there is no restrict in this framework,there will be a circle-depending like this:
{
data:{
foo:function(){
return this.bar+1;
},
bar:function(){
return this.foo+1;
}
}
}
to resolve this problem,the author abstract the data model into 2 levels,one is pure variable(data),the other one is data which depend on the previous level(computed).the second level values can refer to some first level values,but not the other way.and,the second values can not refer to a second level values.
in this way,there will never be a circle-depending,this is the benefit.but on the other hand,it make the API more complex and hard to understand.

q2:is there really an answer in the documentation for this question?
a:i don’t know

I’m sorry, but you really need to RTFM.

1 Like