Manually recalculate 'computed properties'

前提是你 提交于 2019-12-10 14:55:40

问题


If I have a custom element

Polymer({
  name: 'dane',

  computed: {
    message: 'greet(name)'
  },

  greet: function(name) {
    return 'hello ' + name + Date.now();
  }
})

When I change name polymer will automatically recompute message, but is there a way to recompute message without changing name?


回答1:


You could add another input value to the compute expression, i.e.:

message: 'greet(name,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.



来源:https://stackoverflow.com/questions/27206003/manually-recalculate-computed-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!