给 router-view 添加 key, 改变 key 时 router-view 将会创建刷新.
使用 Vue ref
创建变量.
import { ref } from "vue";
export const routeViewKey = ref(Math.random().toString());
export const reloadRouteView = () => {
routeViewKey.value = Math.random().toString();
};
将routeViewKey
作为 router-view 的 key.
<router-view :key="routeViewKey"></router-view>
import { routeViewKey } from "yourpath";
export default {
setup() {
return { routeViewKey };
},
};
使用
调用reloadRouteView
即可.