【发布时间】:2017-09-11 06:21:11
【问题描述】:
我想为不同自定义元素中的计算绑定使用共享函数。这可能吗?
无论我如何导入共享函数,都会出现控制台错误:
method `formatAmount` not defined
计算的绑定类似于:
<span>[[formatAmount(amount)]]</span>
我尝试在元素上方使用标签。我在元素内部尝试过。我已经在 index.html 中尝试过。
是否所有计算绑定方法都需要在自定义元素中定义且不能共享?我必须使用 mixin 吗?
更新:我创建了一个丑陋的工作,我在我的自定义元素上定义了一个调用共享方法的私有方法。然后在计算绑定中使用私有方法。由于额外的样板,这很难看。
...
<script src="format-amount.js"></script>
<dom-module id="my-foo">
<template>
...[[_formatAmount(amount)]]...
</template>
<script>
class MyFoo extends Polymer.Element {
...
_formatAmount(amount) {
return formatAmount(amount); // Defined in format-amount.js.
}
}
</script>
</dom-module>
【问题讨论】:
标签: polymer polymer-2.x