首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Polymer2中将Polymer.AppNetworkStatusBehavior扩展为自定义Mixin?

如何在Polymer2中将Polymer.AppNetworkStatusBehavior扩展为自定义Mixin?
EN

Stack Overflow用户
提问于 2017-10-23 15:18:48
回答 1查看 116关注 0票数 0

在Polymer 1.0中,我有以下代码片段:

代码语言:javascript
复制
CustomBehaviorImpl = {
  properties: {
    // Define property here...
    // ...
  },
  // Other custom behaviors definition
  // ...
};

CustomBehavior = [
  Polymer.AppNetworkStatusBehavior,
  CustomBehaviorImpl,
];

如何在Polmery2.0中创建一个CustomMixin类。

EN

回答 1

Stack Overflow用户

发布于 2017-10-23 15:33:56

如果将混入分离到它自己的文件中,则每当合成使用混入的元素时,都可以将它们作为Html Import依赖项引用。只需使用您的自定义行为扩展您的聚合物类。

我认为这个问题已经在stackoverflow上得到了回答。

看一下这个:

Applying Behaviors with JS Mixins in Polymer 2

示例

这是我的CustomMixin.html

代码语言:javascript
复制
<script>

  // CustomMixin provides the _customMixin function

  var CustomMixin = function(superClass) {
     return class extends superClass {

        _customMixin() {

        }

     }
  }
</script>

这是我的聚合物元素,我在这里使用CustomMixin。

代码语言:javascript
复制
<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>

我实际上从未测试过该代码,但我相信这应该是实现自定义混入的方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46883820

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档