首页 > 其他分享 >vue3 + vite 监听路由

vue3 + vite 监听路由

时间:2022-12-02 18:46:57浏览次数:41  
标签:vue import watch onBeforeRouteUpdate vue3 router vite 监听 路由

1. watch监听


import { watch} from 'vue'
import {useRouter} from 'vue-router'
let router = useRouter()
watch(() =>router.currentRoute._value,(m,n)=> {
        console.log('watch',m)
},{ immediate: true })

2. onBeforeRouteUpdate 导航守卫


// f5 刷新不触发
import { onBeforeRouteUpdate } from 'vue-router'
onBeforeRouteUpdate((to) => {
        console.log('to',to)
 });

标签:vue,import,watch,onBeforeRouteUpdate,vue3,router,vite,监听,路由
From: https://www.cnblogs.com/zhang-hong/p/16945327.html

相关文章