分析原因:antdesignvue的前端是一次性渲染的,所以defaultExpandedRowKeys等只在渲染时有效。
解决方法:添加判断v-if你的DataSource
长度,如果为0则不渲染。
动态解决方法:在DataSource赋值的时候,使用splice将其长度变为0
this.DataSource.splice(0)
<a-row class="tree-box">
<a-col>
<a-tree
v-if="DataSource.length>0"
v-model="checkedKeys"
checkable
:auto-expand-parent="autoExpandParent"
defaultExpandAll
:tree-data="DataSource"
/>
</a-col>
</a-row>