需求描述:
Tree 樹形結構,默認展開第二級菜單。
查 element 文檔:
解決方法:
設置 :default-expanded-keys 的值為 idArr 數組,
<el-tree :data="aProductTree" node-key="productCode" :default-expanded-keys="idArr" @node-click="handleNodeClick" style="width: 90%"></el-tree>
在 js 里將data的id push 到 idArr 數組里
export default { data(){ idArr:[] }, method: { this.aProductTree.forEach(m=>{ this.idArr.push(m.id) }) } }