(1)在app.vue
<template>
<router-view v-if="isRouterAlive" />
</template>
<script>
import { defineComponent, ref, nextTick, provide } from 'vue';
export default defineComponent({
setup() {
// 局部组件刷新
const isRouterAlive = ref(true);
const reload = () => {
isRouterAlive.value = false;
nextTick(() => {
isRouterAlive.value = true;
});
};
provide("reload", reload);
return {
isRouterAlive,
};
}
})
</script>
子组件里面调用
import { inject } from "vue";
//刷新图标 //刷新事件
const renovate = inject("reload");
在接口调用成功之后可以使用 renovate();达成刷新页面的效果