Element-Plus el-table lazy 自动更新子列表

Element-Plus el-table组件 设置为lazy 加载子列表时,如果子列表处于打开状态,这时打开弹窗新增一条子列表记录,子列表不会刷新

这篇文章利用映射resolve回调函数,实现更新某一个父行下的子列表

复制代码
<el-table row-key="id" v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"
      @selection-change="handleRowCheckboxChange" :load="load" lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
      <el-table-column type="selection" width="55" />
      <el-table-column label="页面或接口名称" align="center" prop="name" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="父节点ID" align="center" prop="parentId" />
      <el-table-column label="菜单类型" align="center" prop="menuType">
        <template #default="scope">
          <el-tag v-if="scope.row.menuType == 0" type="primary">页面</el-tag>
          <el-tag v-else-if="scope.row.menuType == 1" type="primary">页面下的接口</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="客户端类型" align="center" prop="clientType">
        <template #default="scope">
          <el-tag v-if="scope.row.clientType == 0" type="primary">app</el-tag>
          <el-tag v-else-if="scope.row.clientType == 1" type="primary">h5</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="页面或接口路径" align="center" prop="path" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="当前记录层级" align="center" prop="level" />
      <el-table-column label="操作" align="center" min-width="120px">
        <template #default="scope">
          <el-button link type="primary" @click="openForm('create',null, scope.row.id)"
            v-hasPermi="['jszj:mobile-menu:update']" v-if="scope.row.level == 1">
            添加
          </el-button>

          <el-button link type="primary" @click="openForm('update', scope.row.id)"
            v-hasPermi="['jszj:mobile-menu:update']">
            编辑
          </el-button>
          <el-button link type="danger" @click="handleDelete(scope.row.id)" v-hasPermi="['jszj:mobile-menu:delete']">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>


  const lastTimeParentIdAdd = ref() 


 /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await MobileMenuApi.getMobileMenuPage(queryParams)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
      if (lastTimeParentIdAdd.value != null) {
        refreshChildren(lastTimeParentIdAdd.value);
      }
    }
  }

  /** 添加/修改操作 */
  const formRef = ref()
  const openForm = (type: string, id?: number, parentId?: number) => {
    formRef.value.open(type, id, parentId)

    lastTimeParentIdAdd.value = parentId;
  }

const pNodeResolveMap = reactive({})

  const load = async (
    row,
    treeNode: unknown,
    resolve: (date) => void
  ) => {
    const data = await MobileMenuApi.getByParentId(row.id)
    resolve(data);

    pNodeResolveMap[row.id] = resolve;
  }

  const refreshChildren = async (parentId) => {
    console.log(parentId);

    const resolve = pNodeResolveMap[parentId];
    if (resolve == null) {
      return;
    }

    const data = await MobileMenuApi.getByParentId(parentId)

    resolve(data);

    console.log('刷新完成')
  }
相关推荐
jzlhll12318 分钟前
kotlin Flow first() last()总结
开发语言·前端·kotlin
蓝冰凌1 小时前
Vue 3 中 defineExpose 的行为【defineExpose暴露ref变量】详解:自动解包、响应性与实际使用
前端·javascript·vue.js
奔跑的呱呱牛1 小时前
generate-route-vue基于文件系统的 Vue Router 动态路由生成工具
前端·javascript·vue.js
sp42a1 小时前
在 NativeScript-Vue 中实现流畅的共享元素转场动画
vue.js·nativescript·app 开发
柳杉2 小时前
从动漫水面到赛博飞船:这位开发者的Three.js作品太惊艳了
前端·javascript·数据可视化
Greg_Zhong2 小时前
前端基础知识实践总结,每日更新一点...
前端·前端基础·每日学习归类
We་ct2 小时前
LeetCode 148. 排序链表:归并排序详解
前端·数据结构·算法·leetcode·链表·typescript·排序算法
IT_陈寒3 小时前
JavaScript开发者必看:5个让你的代码性能翻倍的隐藏技巧
前端·人工智能·后端
还是大剑师兰特3 小时前
Vue3 中 computed(计算属性)完整使用指南
前端·javascript·vue.js