手动重新计算“计算属性" [英] Manually recalculate 'computed properties'
本文介绍了手动重新计算“计算属性"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个自定义元素
If I have a custom element
Polymer({
name: 'dane',
computed: {
message: 'greet(name)'
},
greet: function(name) {
return 'hello ' + name + Date.now();
}
})
当我更改name
时,聚合物将自动重新计算message
,但是有没有一种方法可以在不更改name
的情况下重新计算message
?
When I change name
polymer will automatically recompute message
, but is there a way to recompute message
without changing name
?
推荐答案
您可以在计算表达式中添加另一个输入值,即:
You could add another input value to the compute expression, i.e.:
message: 'greet(name,x)'
,然后通过更新x强制重新计算.
and then force a re-compute by updating x.
请记住,计算属性是只读的,因此您不能直接为其分配值.
Keep in mind computed properties are read-only so you can't directly assign it a value.
这篇关于手动重新计算“计算属性"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文