Ant Design Vue 中 Tree 树形控件 defaultExpandAll 设置无效
生活随笔
收集整理的這篇文章主要介紹了
Ant Design Vue 中 Tree 树形控件 defaultExpandAll 设置无效
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題: 在代碼中設置了default-expand-all屬性 樹形結構還是沒有展開
原因: 因為default-expand-all屬性是用來設置默認值的,而初始值treeData通常情況下是需要調異步請求來獲取數據的 默認是空數組,在treeData是空數組的時候<a-tree>組件已經渲染了,沒有樹結構節點所以default-expand-all屬性看起來也沒有發揮作用了。
解決: 在渲染<a-tree>組件的時候先判斷treeData數組長度大于0才渲染
<template>// ...<a-tree v-if="treeData.length > 0" :tree-data="treeData" default-expand-all ></a-tree>// ... </template> // ... data() {return {treeData: []} }, created() {this.getDataList() }, methods: {getDataList () {// 模擬異步請求setTimeout(function () {this.treeData = [{title: '湖濱銀泰集團',key: '99232344',children: [{ title: 'in77杭州銀泰', key: '99232377' },{ title: 'in99上海銀泰', key: '99232399' },],},]}, 400)} } // ... 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Ant Design Vue 中 Tree 树形控件 defaultExpandAll 设置无效的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Django MPTT —— 安装
- 下一篇: 134. Gas Station 加油站