Vue+Element中Table懒加载(loads属性)删除后无法及时更新

 

 所需参数设置:

data () {
    return {
      maps: new Map()
    }
  },

 table: 

设置:

ref="table"

ref需要设置,后面会用到

 <el-table
        v-loading="dataListLoading"
        ref="table"
        :data="dataList"
        row-key="id"
        border
        style="width: 100%;"
        :max-height="tableHeight"
        lazy
        :load="load"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      >

 核心代码:

const { pid } = row
const { tree, treeNode, resolve } = this.maps.get(pid)
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, [])
this.load(tree, treeNode, resolve)

删除功能完整代码如下: 

deleteRow (row) {
      console.log(row)
      if (row.children.length !== 0) {
        this.$message.warning('请先删除子节点!')
        return
      }

      this.$confirm('确认进行删除操作?', {
        confirmButtonText: this.$t('confirm'),
        cancelButtonText: this.$t('cancel'),
        type: 'warning'
      }).then(() => {
        this.$http.delete('url', { 'data': [row.id] }).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500

          })
          this.getDataList()
          const { pid } = row
          const { tree, treeNode, resolve } = this.maps.get(pid)
          this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, [])
          this.load(tree, treeNode, resolve)
        }).catch(() => {
        })
      }).catch(() => { })
    }

load核心代码

const pid = tree.id
this.maps.set(pid, { tree, treeNode, resolve })

 load完整代码:

load (tree, treeNode, resolve) {
      const pid = tree.id
      this.maps.set(pid, { tree, treeNode, resolve })
      this.$http.get('url', {
        params: {
          pid: tree.id
        }
      }).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        let list = res.data
        let newArr = list.map(v => {
          return { ...v, hasChildren: v.grade === 1 }
        })
        resolve(newArr)
      }).catch(() => { })
    }

参考地址:

https://blog.csdn.net/weixin_42225341/article/details/94740238 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值