計(jì)算屬性是不是只在第一次計(jì)算的時(shí)候收集使用到的屬性,之后當(dāng)這些屬性變化的時(shí)候,會(huì)重新計(jì)算屬性??例如,下面的例子,prefix屬性會(huì)每秒變化一次,但prefix屬性的變化不會(huì)導(dǎo)致upper計(jì)算屬性的變化。是不是因?yàn)榈谝淮螆?zhí)行計(jì)算屬性的時(shí)候,沒有訪問到prefix(因?yàn)閕f條件),之后,prefix變化也不會(huì)導(dǎo)致計(jì)算屬性重新調(diào)用??{{upper}}varxyz=newVue({el:'#app',data:{name:'xx',prefix:'A',suffix:'Y'},computed:{upper:function(){var_this=this;console.log('recompute:'+this.name);if(_this.suffix.length>10)returnthis.name.toUpperCase()+"+"+this.prefix;returnthis.name.toUpperCase()+"_"+this.suffix;}},mounted:function(){var_this=this;this.timer=setInterval(function(){if(_this.name.length>100||_this.suffix.length>50||_this.prefix.length>50)return;_this.prefix=_this.prefix+_this.prefix;console.log("timer...prefix:"+_this.prefix);},1000);},beforeDestory:function(){if(this.timer){clearInterval(this.timer);}}});
計(jì)算屬性是不是只在第一次計(jì)算的時(shí)候收集使用到的屬性,第一次未收集到的屬性值變化不會(huì)導(dǎo)致計(jì)算屬性變化???大佬們有什么好的建議?
守候你守候我
2019-11-03 15:51:17