VUE + element-ui实现当前页面/表格刷新方法

之前在做elementui的项目,一些新增,编辑,删除等操作后,需要刷新当前页面或者表格,看官方文档没找到合适的方法,之前是直接重新再调一遍后台接口进行数据的刷新,今天发现一个不错的方法,来记录一下

App.vue中配置入下

复制代码
<template>
  <div id="app">
     <router-view v-if="isRouterAlive"></router-view>
  </div>
</template>
 
<script>
  export default {
    name: 'App',
    provide(){
        return {
            reload: this.reload
        }
    },
    data(){
        return {
            isRouterAlive:true
        }
    },
    methods:{
        reload(){
            this.isRouterAlive=false
            this.$nextTick(()=>this.isRouterAlive=true)
        }
    },
  }
</script>
复制代码

需要使用的页面中调用如下

复制代码
export default {
   inject:['reload'],
   components:{
       AddEditDialog
   },
   data() {
    return {
    } } }
复制代码
复制代码
//删除
del(){
   if(this.currentRow.id!==undefined){
       const data = {
           id: this.currentRow.id
       }
       this.$store.dispatch('deleteEnterprise',data)
       const data1 = {
         keyWord:''
       }
       setTimeout(()=>{this.$store.dispatch('getEnterpriseList',data1)},500)//表格重载
                    
   }else{
       this.$store.dispatch('ShowMsg',{value:'请选中删除对象',type:'error'})
       this.reload()
   }
},
复制代码

在使用的页面中 this.reload()直接调用即可

原文链接地址:https://blog.csdn.net/weixin_41127584/article/details/102569411

posted @   慕雪琳鸢  阅读(6693)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示