项目目录下 app.vue 页面
<template>
<router-view v-if="isRouterAlive" />
</template>
<script setup lang="ts">
import { ref, provide } from "vue";
const isRouterAlive = ref(true);
const reload = () => {
isRouterAlive.value = false;
setTimeout(() => {
isRouterAlive.value = true;
}, 0);
};
provide("reload", reload);
</script>
<style lang="scss">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
nav {
padding: 30px;
a {
font-weight: bold;
color: #2c3e50;
&.router-link-exact-active {
color: #42b983;
}
}
}
</style>
在使用的 .vue文件中
import { inject } from "vue";
const reloads: any = inject("reload");
直接调取方法
reloads();