解决vue3多路由跳转同一页面,网址更新页面不更新的问题
- 解决方法:在当前页面监听路由,在组件上绑定key
- 代码:下面展示一些
内联代码片
。
// 组件
<Model :key="times" />
// 监听路由
import { ref, reactive, onMounted, watch } from "vue";
import { useRouter} from "vue-router";
const router = useRouter();
const times = ref(new Date().getTime());
watch(
() => router.currentRoute.value,
(n) => {
times.value = new Date().getTime();
},
{ immediate: true, deep: true }
);