简体   繁体   English

Polymer 3使用behaivor的方式是什么?

[英]What is the Polymer 3 way of using behaivors?

What's the proper way of using iron-overlay-behavior in Polymer 3. Shouldn't that be as simple as extending the class? 在Polymer 3中使用铁覆盖行为的正确方法是什么?这不应该像扩展类那样简单吗? But I ain't sure because my component already extends PolymerElement. 但是我不确定,因为我的组件已经扩展了PolymerElement。

Any simple example should help. 任何简单的例子都应该有所帮助。

Have you looked at the Polymer.mixinBehaviors() helper function? 您是否看过Polymer.mixinBehaviors()辅助函数? Behaviors are superseded by mixins as of Polymer 2, and as far as I can tell the version 3 does not bring any changes in that regard. 从Polymer 2开始,行为已被mixins取代,据我所知,版本3在这方面没有带来任何变化。

Here is how you would use iron-overlay-behavior in a Polymer 3 element: 这是在Polymer 3元素中使用iron-overlay-behavior

import {PolymerElement} from '@polymer/polymer';
import {IronOverlayBehavior} from '@polymer/iron-overlay-behavior';
import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';

class MyOverlay extends
  mixinBehaviors([IronOverlayBehavior], PolymerElement) {
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM