el-tree 设置默认选中不起作用
1、原因
先初始化了选中得keys ,后期初始化得树节点无法被设置
2、代码
<el-tree :data="data" show-checkbox node-key="id" :default-checked-keys="selectedArr" @check-change="handleCheckChange" > </el-tree>
data() { return { data: [], selectedArr:[], }; }, methods: { handleCheckChange(data, checked, indeterminate) { showPointLayer(data.id, checked); }, async initTreeNodes() { const { data: res } = await getLayerTreeNodes(); if (res.result.length > 0) { this.data.push({ label: "图层树", id: '99', children: res.result, }); } }, }, mounted() { //树绑定完数据之后 再初始化选中得数组 this.initTreeNodes().then(()=>{ this.selectedArr= this.data[0].children.map(o=>{ return o.id }) }); }, };