1. 在App.vue 文件里写入provide 方法
html
<script setup></script>
<template>
<a-config-provider :locale="localezhCN" :autoInsertSpaceInButton="false">
<el-config-provider :locale="locale">
<router-view v-wechat-title="$route.meta.title" v-if="isRouterAlive" />
</el-config-provider>
</a-config-provider>
</template>
<script>
import zhCn from "element-plus/es/locale/lang/zh-cn";
import zhCN from "ant-design-vue/es/locale/zh_CN";
export default {
//局部组件
components: {},
//lu
data() {
return {
isRouterAlive: true,
};
},
setup() {
//设置中文
return {
locale: zhCn,
localezhCN: zhCN,
};
},
//lu
provide() {
return {
reload: this.reload,
};
},
//lu
methods: {
async reload() {
this.isRouterAlive = false;
await this.$nextTick();
this.isRouterAlive = true;
},
},
};
</script>
<style>
@import url("./assets/css/base.css");
</style>
2. 在需要刷新的页码使用inject引入
html
<script>
export default {
inject:['reload'], //注入依赖
mounted() {
if (location.href.indexOf("#Case") == -1) {
location.href = location.href + "#Case";
this.reload();
}
}
}
</script>