vue3组件内判断是否进行路由跳转

    import { onBeforeRouteLeave } from 'vue-router'
	import { ElMessageBox} from 'element-plus'

	onBeforeRouteLeave((to,from,next)=>{
        if(form.content.trim()){
            ElMessageBox.confirm(
	            '内容还未提交,确定要离开此页面吗?',
	            '提示',
	            {
	                confirmButtonText: '确定',
	                cancelButtonText: '取消',
	                type: 'warning',
	            }
	        )
            .then(() => {
                next()
            })
            .catch(() => {
                console.log(111);
            })
        }else{
           next() 
        }
    })

你可能感兴趣的:(Vue,javascript,前端,vue.js)