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>
相关推荐
love530love1 天前
Scoop 完整迁移指南:从 C 盘到 D 盘的无缝切换
java·服务器·前端·人工智能·windows·scoop
i220818 Faiz Ul1 天前
计算机毕业设计|基于springboot + vue鲜花商城系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
王码码20351 天前
Flutter for OpenHarmony:Flutter 三方库 bluez 玩转 Linux 风格的蓝牙操作(蓝牙底层互操作)
linux·运维·服务器·前端·flutter·云原生·harmonyos
暴力袋鼠哥1 天前
基于 Spring Boot 3 + Vue 3 的农产品在线销售平台设计与实现
vue.js·spring boot·后端
chilavert3181 天前
技术演进中的开发沉思-371:final 关键字(中)
java·前端·数据库
2301_816997881 天前
Vite构建工具
前端
yuki_uix1 天前
深入理解 reduce:从面试题到设计思维
前端
凌云拓界1 天前
TypeWell全攻略(二):热力图渲染引擎,让键盘发光
前端·后端·python·计算机外设·交互·pyqt·数据可视化