1提示框中,有时需要click事件,但是formater中的不会指向Vue
例如点击查看,去往地区详情页面。
但直接onclick或a标签是不会走路由刷新的。
会导致页面刷新,不是路由跳转。

2watch解决
ecahrt提示框中,可以用temp第三方变量,watch监听,再手动绑定addeventListener。
data(){
return {
hookToolTip
}
watch:{
hookToolTip:function(name) {
let self=this
document.querySelector("#btn-tooltip").addEventListener("click", () => {
this.$router.push({ path: '/home', query: { name: name }});
})
}
}
tooltip: {
trigger: "item",
triggerOn: "click",
enterable: true,//鼠标是否可进入提示框浮层中属性默认为 false,如果不设置为true的话,无法操作提示框里的 button
formatter: function (params) {
_this.hookToolTip = params.name;
return res = `
<span>xx站</span>
<i id="btn-tooltip" class="el-icon-tickets"></i>
</div>`//``es6字符模板,方便排版
}
参考资料:
https://www.jianshu.com/p/ce4d06c10e23
https://blog.csdn.net/zeng092210/article/details/99645107(详细参考评论中...)
网友评论