vue3.0之如何获取当前路由地址
三种方式
import { defineComponent, ref, reactive, watch, toRaw, getCurrentInstance } from 'vue';
const { proxy }: any = getCurrentInstance(); console.log(proxy.$router.currentRoute.value); const router = useRouter(); console.log(router.currentRoute.value); watch( () => router, (newValue, oldValue) => { console.log(newValue.currentRoute.value, '新的路由'); console.log(newValue.currentRoute.value, '旧的路由'); }, { immediate: true } );