• 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')

在这里插入图片描述

Logo

前往低代码交流专区

更多推荐