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>
相关推荐
华科易迅1 分钟前
Vue如何集成封装Axios
前端·javascript·vue.js
康一夏2 分钟前
Next.js 13变化有多大?
前端·react·nextjs
糖炒栗子03262 分钟前
前端项目标准环境搭建与启动
前端
不是az3 分钟前
CSS知识点记录
前端·javascript·css
爱分享的阿Q11 分钟前
GPT6-Spud-AGI前夜的豪赌
前端·easyui·agi
昵称暂无140 分钟前
.NET 高级开发 | i18n 原理、实现一个 i18n 框架
javascript·c#·.net
西西小飞龙41 分钟前
Less/Sass Mixins vs. Extend
前端·less·sass
syjy244 分钟前
(含下载)BeTheme WordPress主题使用教程
前端·wordpress·wordpress建站
Misnice1 小时前
shadcn如何使用
前端·reactjs
h_jQuery1 小时前
vue使用gm-crypto对数据进行sm4加密处理
前端·javascript·vue.js