Ant Design Vue Tree 树形控件

博客涉及前端领域相关内容,包含JavaScript、Vue.js、HTML、jQuery等技术,这些技术在前端开发中应用广泛,能助力构建丰富多样的网页和应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<a-tree
    checkable
    v-model="menuIds"
	v-if="menuTreeData"
	:tree-data="menuTreeData"
	:defaultExpandAll="true">
</a-tree>

 

methods: {
	// 集合转树
	list2Tree(list, originList) {
		list.forEach(d => {
		    let children = originList.filter(f => f.parentId === d.id)
		    if (children && children.length > 0) {
			    d.children = children;
			    this.list2Tree(children, originList);
		    }
	    })
	},
    load() {
        this.$post("/api/query").then(data => {
			let menuTreeData = JSON.parse(JSON.stringify(data))
		}).catch(err => {})
        // 传入需要转换树结构的数据
        this.list2Tree(menuTreeData, menuTreeData)
        // 0为顶层
        this.menuTreeData = menuTreeData.filter(f => f.parentId === 0)
    }
}
Ant-design-vue树形控件tree是一个用于展示层级关系的组件,可以展示树形结构的数据,支持展开、折叠、选择、拖拽等交互操作。以下是Ant-design-vue树形控件tree的基本用法: 1. 安装Ant-design-vue组件库: ```bash npm install ant-design-vue --save ``` 2.Vue组件中引入Ant-design-vue树形控件tree: ```vue <template> <a-tree :tree-data="treeData"></a-tree> </template> <script> import { Tree } from 'ant-design-vue'; export default { components: { 'a-tree': Tree, }, data() { return { treeData: [ { title: 'Parent 1', key: '0-0', children: [ { title: 'Child 1-1', key: '0-0-0', }, { title: 'Child 1-2', key: '0-0-1', }, ], }, { title: 'Parent 2', key: '0-1', children: [ { title: 'Child 2-1', key: '0-1-0', }, { title: 'Child 2-2', key: '0-1-1', }, ], }, ], }; }, }; </script> ``` 3. 可以通过设置props属性实现更多的功能,例如: ```vue <a-tree :tree-data="treeData" :show-line="true" :default-expanded-keys="['0-0', '0-1']" @select="handleSelect"></a-tree> ``` 上述代码中,设置了show-line为true,表示展示连接线;设置了default-expanded-keys为['0-0', '0-1'],表示默认展开树形结构的节点;使用@select监听选择事件,执行handleSelect方法。 Ant-design-vue树形控件tree还支持其他交互操作,例如:拖拽节点、异步加载数据、自定义节点等。具体使用方式可以参考官方文档:https://www.antdv.com/docs/vue/tree-cn/。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值