我目前项目基于element-ui+vue+router架构的平台,我会每天总结一点遇到的坑和解决方案,以备后续查阅解决。
需求描述
用户跳转到固定页面时,判断用户是否登录,未登录使用element的 $confirm弹窗跳转登录。
无法使用router.push。。等。
解决方法
Vue.prototype.$confirm('请先登录获取查看权限', '提示', {
confirmButtonText: '前往登录',
showCancelButton:false,
type: 'warning'
}).then(() => {
console.log('成功')
next({
replace:true,
name:'login',
})
}).catch(() => {
});
使用如下,name为router中定义的路由的名字
next({
replace:true,
name:'login',
})