我有这个Vue.js代码:
new Vue({
data:{
myValue:'x',
myOtherValue:'y'
},
computed: {
myComputed: myFunction(){
return this['my' + 'Value']
}
}
})
如您所见,计算(computed)属性将被缓存,并且它仅依赖于data.myValue
.我的问题是如何Vue.js缓存系统知道只有在myValue
发生变化时才能再次运行计算函数吗?
如果我更改myOtherValue
变量,myComputed
函数将使用缓存,并且在调用它时不会再次运行.
我想了好几种可能的方法.但Vuej是怎么做到的?
在这段代码中会发生什么,它将依赖于什么?
const flag=2
new Vue({
data:{
myValue:'x',
myOtherValue:'y'
},
computed: {
myComputed: myFunction(){
if (flag==1){
return this['my' + 'Value']
}
else
return this['my' + 'Other' + 'Value']
}
}
})
Bonus:如果我能链接到VueJS代码中的相关函数,我将不胜感激:https://github.com/vuejs/vue