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>
相关推荐
努力往上爬de蜗牛2 分钟前
el-table列表修改某个输入框输入 卡顿问题修改
javascript·vue.js·elementui
深念Y3 分钟前
一个Bug:Vue Router 4.3.0 导致浏览器窗口无法最小化
前端·vue.js·bug·窗口·最小化·bilibili·视频网站
湛海不过深蓝4 分钟前
【procomponents】根据表单查询表格数据的两种写法
前端·javascript·react.js
大Mod_abfun5 分钟前
AntdUI教程#1ChatList交互(vb.net)
服务器·前端·ui·交互·antdui·聊天框
Beth_Chan7 分钟前
Stock Trading - React
javascript·react.js
憧憬成为web高手7 分钟前
xss学习记录--xss-lab部署
前端·学习·xss
窝子面7 分钟前
十四、弹窗组件
前端
局i8 分钟前
从零封装第一个 Vue 组件:极简入门指南
前端·javascript·vue.js