element实现当前页面/表格刷新方法

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()直接调用即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值