在Polymer 1.0中,我有以下代码片段:
CustomBehaviorImpl = {
properties: {
// Define property here...
// ...
},
// Other custom behaviors definition
// ...
};
CustomBehavior = [
Polymer.AppNetworkStatusBehavior,
CustomBehaviorImpl,
];如何在Polmery2.0中创建一个CustomMixin类。
发布于 2017-10-23 15:33:56
如果将混入分离到它自己的文件中,则每当合成使用混入的元素时,都可以将它们作为Html Import依赖项引用。只需使用您的自定义行为扩展您的聚合物类。
我认为这个问题已经在stackoverflow上得到了回答。
看一下这个:
Applying Behaviors with JS Mixins in Polymer 2
示例
这是我的CustomMixin.html
<script>
// CustomMixin provides the _customMixin function
var CustomMixin = function(superClass) {
return class extends superClass {
_customMixin() {
}
}
}
</script>这是我的聚合物元素,我在这里使用CustomMixin。
<link rel="import" href="../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../CustomMixin/CustomMixin.html">
<dom-module id="my-element">
<template>
<style>
:host {
display: block;
}
</style>
</template>
<script>
class MyElement extends CustomMixin(Polymer.Element) {
static get is() { return 'my-element'; }
static get properties() {
return {
};
}
ready() {
super.ready();
}
}
window.customElements.define(MyElement.is, MyElement);
</script>
</dom-module>我实际上从未测试过该代码,但我相信这应该是实现自定义混入的方法。
https://stackoverflow.com/questions/46883820
复制相似问题