我想将几个组件和元素组合在一起,我怎么能用 Sencha ExtWebComponents 做到这一点?
例如:
<div>View</div>
<ext-button></ext-button>
我想将几个组件和元素组合在一起,我怎么能用 Sencha ExtWebComponents 做到这一点?
例如:
<div>View</div>
<ext-button></ext-button>
这是一个简单的示例,说明如何组合 Web 组件。
使用组件:
在 index.js 中,我已经导入了按钮组件并使用import './SandboxViewComponent';
在 index.html 中,我用<my-sandbox-view></my-sandboxy-view>
.
来源如下
SandboxViewComponent.js
import template from './SandboxViewComponent.html';
class SandboxViewComponent extends HTMLElement {
constructor() {
super()
this.innerHTML = template;
}
connectedCallback() {
var me = this;
// Add after the buttonEl.ext.el is instantiated
setTimeout(() => {
setTimeout(() => {
me._addListeners();
}, 0);
}, 0);
}
disconnectedCallback() {
}
attributeChangedCallback(attrName, oldVal, newVal) {
}
_addListeners() {
var buttonEl = this.querySelector("ext-button");
button.ext.on("tap", function () {
alert("tap 1 works");
});
button.ext.addListener("tap", function() {
alert("tap 2 works");
});
buttonEl.ext.el.on('click', () => {
alert('ext on click works');
});
}
}
window.customElements.define('my-sandbox-view', SandboxViewComponent);
SandboxViewComponent.html
<div>Sandbox View</div>
<ext-button
text="Button 1"
shadow="true"
arrowAlign="bottom"
></ext-button>