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) => {reactive to
console.log(newValue.currentRoute.value, '新的路由');
console.log(newValue.currentRoute.value, '旧的路由');
},
{ immediate: true }
);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。