- 对组件添加一个删除按钮。在点击删除按钮时移除组件。执行如下步骤来在组件内添加删除按钮及删除事件:
static template = xml`
<div style="display: flex;align-items: center;" class="bg-info text-center p-2" >
<div>
<b> Welcome to dtcloud </b>
<div style="width:100%;display: flex;justify-content: center;">
<i class="fa fa-close p-1 float-right" style="cursor: pointer;" t-on-click="onRemove"> </i>
</div>
</div>
- 要删除该组件,对 MyComponent 类添加一个 onRemove 方法,如下:
class MyComponent extends Component {
static template = xml`
<div style="display: flex;align-items: center;" class="bg-info text-center p-2" >
<div>
<b> Welcome to dtcloud </b>
<div style="width:100%;display: flex;justify-content: center;">
<i class="fa fa-close p-1 float-right" style="cursor: pointer;" t-on-click="onRemove"> </i>
</div>
</div>
</div>`
onRemove(ev) {
this.destroy();
}
}
- 更新模块应用修改。更新完成后,会在横栏的右上角看到如下图所示的叉形图标:
- 点击删除按钮,会删除掉我们的 OWL 组件。重新加载后横栏会再次出现。