我在切换选项卡的时候会根据用户的选择来决定是否切换选项卡,选项卡用的是elemenui的tabs组件,我看文档中有一个before-leave的方法如图:我的代码:this.$confirm('您还未保存简介,确定需要离开吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => { return true;
}).catch(() => { return false
});当我选择取消的时候会returnfalse,但是这样并没有阻止切换,于是我隐隐感觉要用文档中的这句话来阻止“返回 Promise 且被 reject,则阻止切换。”,但是实在不知道怎么写,求指教
2 回答
偶然的你
TA贡献1841条经验 获得超3个赞
直接把$confirm
return
回去试下,因为$confirm
本来就是返回一个Promise
return this.$confirm('您还未保存简介,确定需要离开吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
试试这个:
return new Promise((res,rej)=>{ this.$confirm('您还未保存简介,确定需要离开吗?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { res() }).catch(() => { rej() }); } )
添加回答
举报
0/150
提交
取消