用于取消各种冒泡事件,如下面的点击事件冒泡:
<button @click="cancelBubbling">按钮</button>
function cancelBubbling(e) {
if (!!e?.stopPropagation) {
e.stopPropagation(); //有stopPropagation属性的直接掉用
} else {
window.event.cancelBubble = true; //没有stopPropagation属性的做下兼容
}
}