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>
相关推荐
小则又沐风a6 分钟前
基础的开发工具(2)---Linux
java·linux·前端
yqcoder6 分钟前
JavaScript 事件流:从“捕获”到“冒泡”的完整旅程
服务器·前端·javascript
普修罗双战士16 分钟前
项目设计-文章系统发布文章完整前后端设计
java·数据库·vue.js·spring boot·git·intellij-idea
Csvn17 分钟前
Vue 3 Composition API 深度解析
前端·vue.js
鹏程十八少18 分钟前
11. 2026金三银四 能答对这 29 道题,你的 Android 插件化就算真正通关了
前端·后端·面试
潇凝子潇1 小时前
使用英伟达免费调用多家大模型API
java·前端·javascript
旷世奇才李先生1 小时前
Vue 3\+Vite\+Pinia实战:前端工程化与组件化开发全指南
前端·vue.js
Beginner x_u1 小时前
前端八股整理(手写 01)|Promise 超时控制、红绿灯与 Promise.all
前端·javascript·promise
周bro1 小时前
vue2+element ui 中的el-table表格 选中当前行当前行变色,单选/多选--------续集:表格样式修改整合
vue.js·ui·elementui
万少10 小时前
Vibe Coding不停歇,移动端 TRAE SOLO 让你用手机也能编程啦
前端·javascript·后端