有了Polymer 1行为,我能够在该行为中放置一个宿主属性。 Polymer 3 Mixins可以做到吗?
聚合物1的行为:
<script>
AccountBehavior = {
properties: {
tabactivated: Boolean
},
observers: ['_refreshActivePosts(tabactivated)'],
_refreshActivePosts: function(tabactivated) {
if (tabactivated) {
this.$.account.refreshAjax();
}
}
}
</script>
答案 0 :(得分:1)
不确定我能确切记得旧的host属性做什么。但是我写了这个module
来查找元素的宿主
export default function domHost(self) {
let parent = self.parentNode;
while(parent && parent.nodeType !== 11) {
parent = parent.parentNode; //work up the hierarchy
}
return parent ? parent.host : self;
}
我经常使用它来将事件侦听器添加到我的托管元素中 像这样:-
connectedCallback() {
super.connectedCallback();
this.domHost = domHost(this);
this.domHost.addEventListener('pas-filelocation-request', this._gotRequest);
}
disconnectedCallback() {
super.disconnectedCallback();
this.domHost.removeEventListener('pas-filelocation-request', this._gotRequest);
}