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>
相关推荐
zhuà!7 分钟前
腾讯地图TMap标记反显,新增标记
前端·javascript·vue.js
未知原色10 分钟前
web worker使用总结(包含多个worker)
前端·javascript·react.js·架构·node.js
ttod_qzstudio21 分钟前
CSS改变图片颜色方法介绍
前端·css
幽络源小助理26 分钟前
SpringBoot+Vue摄影师分享社区源码 – Java项目免费下载 | 幽络源
java·vue.js·spring boot
curdcv_po42 分钟前
我接入了微信小说小程序官方阅读器
前端·微信小程序
程序员鱼皮1 小时前
什么是 RESTful API?凭什么能流行 20 多年?
前端·后端·程序员
+VX:Fegn08951 小时前
计算机毕业设计|基于springboot + vue健身房管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
www_stdio1 小时前
让大语言模型拥有“记忆”:多轮对话与 LangChain 实践指南
前端·langchain·llm
inferno1 小时前
JavaScript 基础
开发语言·前端·javascript
cindershade1 小时前
Intersection Observer 的实战方案
前端