import { TransitionGroup, computed, defineComponent, onMounted, reactive, ref } from 'vue'; import styles from './index.module.less'; import TheSearch from '@/components/TheSearch'; import { NButton, NImage, NSpace } from 'naive-ui'; import { useRouter } from 'vue-router'; import mock from './mock.json'; import { api_musicTagTree } from './api'; export default defineComponent({ name: 'XiaokuAi', setup() { const router = useRouter(); const data = reactive({ tags: [] as any[], tagIndex: 0, tagActive: {} as any, list: mock.list }); const getTags = async () => { const res = await api_musicTagTree(); if (Array.isArray(res?.data)) { data.tags = res.data; const list = renderTag(res.data); console.log(list); } }; // 递归渲染标签 const renderTag = (_data: any[]): any => { const item = { columnName: _data[0].columnName, list: _data.map((item: any) => { return { name: item.name, list: Array.isArray(item.children) ? renderTag(item.children) : [] }; }) }; return item; }; onMounted(() => { getTags(); }); return () => (