使用ant-design-vue的树选择组件TreeSelect
HelloWorld.vue<template><a-tree-select:replace-fields="{children:'children', title:'name', key:'id', value: 'id' }"style="width: 100%":dropdown-style="{ maxHeight: '400px', overflow: 'auto' }
·
- HelloWorld.vue
<template>
<a-tree-select
:replace-fields="{children:'children', title:'name', key:'id', value: 'id' }"
style="width: 100%"
:dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
:tree-data="treeData"
placeholder="Please select"
tree-default-expand-all
>
</a-tree-select>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
interface TreeDataItem {
name:string;
id:string;
children?: TreeDataItem[];
}
const treeData: TreeDataItem[] = [
{
name: 'Node1',
id:"0-0",
children: [
{
name: 'Child Node1',
id: '0-0-1'
},
{
name: 'Child Node2',
id: '0-0-1',
},
],
},
{
name: 'Node2',
id: '0-1'
},
];
export default defineComponent({
setup() {
return {
treeData,
};
},
});
</script>
- App.vue
<template>
<HelloWorld />
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import HelloWorld from './components/HelloWorld.vue';
export default defineComponent({
name: 'App',
components: {
HelloWorld
}
});
</script>
<style>
</style>
- main.ts
import { createApp } from 'vue'
import App from './App.vue'
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
createApp(App).use(Antd).mount('#app')
更多推荐
已为社区贡献19条内容
所有评论(0)