vue3的composition API监听路由
作者:互联网
1、问题:从vue2的obj写法转向vue3的setup写法,要如何在某个组件中监听路由变化呢
2、解决:
<script setup lang='ts'>
import {useRouter} from 'vue-router'
import {watch} from 'vue'
//监听路由变化,判断是否填充整个页面 let router=useRouter() let currentMeta=ref(router.currentRoute.value.meta) watch(()=>router.currentRoute.value,(newVal,oldVal)=>{ currentMeta.value=newVal.meta }) </script>
标签:currentMeta,value,监听,API,meta,vue3,router,composition,路由 来源: https://www.cnblogs.com/lovewhatIlove/p/16454217.html