给 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即可.