mixinsを独自のファイルに分割すると、mixinを使用する要素を作成するたびに、それらをHtml Import依存関係として参照できます。 Polymerクラスをカスタムビヘイビアで拡張するだけです。
私はこの質問は既にここでは、stackoverflowで答えられたと思います。
この1を見てみましょう:
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>
私は実際にそのコードをテストしたことはありませんが、私は、これはカスタムミックスインを実装する方法であるべきと考えています。
「ポリマー2のJS MIxinsでビヘイビアを適用する」を読んだことがありますが、コードが実際にどのように機能するかは実際には理解できませんでした。上記のサンプルに基づいた実際のコードを教えてください。 –
追加のファイルに配置されたカスタムmixinを既存のPolymer要素に追加する方法の例を追加しました。 クラススタイルの要素でハイブリッド動作を使用しています。 – Niklas
私はあなたの例としてカスタムmixinを定義することについて知っています、私の質問は "Polymer2のCustomMixinにPolymer.AppNetworkStatusBehaviorを拡張する方法"でしたか? –