标签:logic exp imp mixin for efault 使用 catch 提示
/**
* what for: check when leave
* how to use:
* step-1: import routeLeaveCheck from ‘@/mixins/router/leave-check‘
* step-2: mixins: [routeLeaveCheck],
* step-3: ???
* define 【 needCheckFlag 】 in your own vue file(default value is true)
* sometime you dont‘ need checking when leave this page(click button, router-link etc..),
* you can change the value to be "false" before such kind operations
*/
export default {
beforeRouteLeave(to, from, next) {
if (this.needCheckFlag) {
this.$confirm(‘确定离开此页面?‘, ‘提示‘, {
confirmButtonText: ‘确定‘,
cancelButtonText: ‘取消‘,
type: ‘warning‘
}).then(() => {
// some logic
next()
})
.catch(() => { next(false) })
} else {
next()
}
}
}
Vue 离开页面时的校验-mixin-beforeRouteLeave
标签:logic exp imp mixin for efault 使用 catch 提示
原文地址:https://www.cnblogs.com/leslie1943/p/13364835.html