我想知道在render里面写的方法怎么阻止事件冒泡和捕获呢?vue的官网只找到了上面的模板写法。
<template>
<Table highlight-row :columns="tabletitle" :data="tablecontent"
@on-current-change="currentchangefn" @on-select="onselectfn"
@on-select-all="onselectallfn" @on-selection-change="onselectionchangefn" border>
</Table>
</template>
<script>
{
title: "操作",
key: "action",
width: 150,
align: "center",
render: (h, params) => {
return h("div", [
h(
"Button",
{
props: {
type: "primary",
size: "small"
},
style: {
marginRight: "5px"
},
on: {
click: () => {
this.viewfn(params);
}
}
},
"查看"
)
]);
}
},
{
title: "启用/锁定",
key: "operate",
width: 150,
align: "center",
render: (h, params) => {
let self = this;
return h("div", [
h("iSwitch", {
props: {
size: "large"
},
on: {
"on-change": () => {
console.log("启用", self, this);
}
}
})
]);
}
}
</script>
table组件的那些方法点击的时候触发一些函数,然后我自己在data里写了个render iSwitch
如下图
比方说,我点击当前这一行(随意一行),触发table的'@on-current-change="currentchangefn" @on-select="onselectfn" @on-select-all="onselectallfn" @on-selection-change="onselectionchangefn"' 这些方法,在控制台console一个1。然后我点击“启用/锁定”的时候console一个2,但是还是会触发这些方法,再console一个1。我感觉应该是 事件冒泡,但是在render函数里怎么阻止事件冒泡没有头绪。有知道的大神给解答一下吧
提完问题就在
vue
的官方文档上找到了render的解释 事件 & 按键修饰符.render函数中 自带event事件,不用传参。不用写e,直接event.stopPropagetion()就可以了。