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('刷新完成')
  }
相关推荐
Mr.app9 小时前
VUE:Ul列表内容自动向上滚动
vue.js
林恒smileZAZ9 小时前
Electron 的西天取经
前端·javascript·electron
这就是佬们吗9 小时前
告别 Node.js 版本冲突:NVM 安装与使用全攻略
java·linux·前端·windows·node.js·mac·web
IT_陈寒9 小时前
2024年JavaScript开发者必备的10个ES13新特性实战指南
前端·人工智能·后端
满栀5859 小时前
基于 jQuery 实现商品列表增删改查与数据统计
前端·javascript·jquery
web小白成长日记9 小时前
CSS 作用域隔离实战:React、Vue 与 Styled Components 的三种范式
前端·css·vue.js·react.js
Mr -老鬼9 小时前
Electron 与 Tauri 全方位对比指南(2026版)
前端·javascript·rust·electron·nodejs·tauri
king王一帅14 小时前
Incremark Solid 版本上线:Vue/React/Svelte/Solid 四大框架,统一体验
前端·javascript·人工智能
智航GIS18 小时前
10.4 Selenium:Web 自动化测试框架
前端·python·selenium·测试工具