vue 当前页面刷新 provide + inject

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>
相关推荐
哈__12 分钟前
ReactNative项目OpenHarmony三方库集成实战:lottie-react-native
javascript·react native·react.js
哈罗哈皮13 分钟前
trea也很强,我撸一个给你看(附教程)
前端·人工智能·微信小程序
就是个名称23 分钟前
echart绘制天顶图
linux·前端·javascript
im_AMBER25 分钟前
Leetcode 147 零钱兑换 | 单词拆分
javascript·学习·算法·leetcode·动态规划
Irene199144 分钟前
Vue3 响应式系统核心对比:effect, track, trigger,computed, watch, watchEffect
vue.js
arvin_xiaoting1 小时前
OpenClaw学习总结_II_频道系统_5:Signal集成详解
java·前端·学习·signal·ai agent·openclaw·signal-cli
哆啦A梦15881 小时前
统一返回包装类 Result和异常处理
java·前端·后端·springboot
saadiya~1 小时前
从插件冗余到极致流畅:我的 Vue 3 开发环境“瘦身”实录
前端·javascript·vue.js
Timer@2 小时前
LangChain 教程 03|快速开始:10 分钟创建第一个 Agent
前端·javascript·langchain
亿元程序员2 小时前
十年游戏程序员开箱实测:这台显示器,彻底改写了我的游戏开发日常
前端