vxe-tree 树组件懒加载的用法

vxe-tree 树组件懒加载的用法,通过 lazy 和 has-child-field 指定 当前节点是否使用异步加载,当点击展开时会自动调用 load-method 去加载子节点

官网:https://vxeui.com/

效果

当节点被勾选是,异步加载后的子节点也会被自动选中

在这里插入图片描述

<template>
  <div>
    <vxe-tree
      lazy
      show-checkbox
      has-child-field="hasChild"
      :node-config="nodeConfig"
      :load-method="loadMethod"
      :data="treeList">
    </vxe-tree>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const nodeConfig = reactive({
  isHover: true
})

const treeList = ref([
  { title: '节点2', id: '2', hasChild: true },
  { title: '节点3', id: '3', hasChild: true },
  { title: '节点4', id: '4', hasChild: true },
  { title: '节点5', id: '5', hasChild: false }
])

const getNodeListApi = (node) => {
  return new Promise(resolve => {
    // 模拟后端接口
    setTimeout(() => {
      resolve([
        { title: `${node.title}-1`, id: `${node.id}1`, hasChild: Math.random() * 10 < 6 },
        { title: `${node.title}-2`, id: `${node.id}2`, hasChild: Math.random() * 10 < 6 }
      ])
    }, 500)
  })
}

const loadMethod = ({ node }) => {
  return getNodeListApi(node)
}
</script>

https://github.com/x-extends/vxe-pc-ui

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值