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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM