这是因为我们data的值没有Value,赋值之后会报错
data
warehouses: [],
解决办法
this.http.post("", keys, true).then(result => {
result.rows.forEach((item, index) => {
if (this.warehouses[index]) {
this.warehouses[index].value = item.WareHouseId;
this.warehouses[index].label = item.Name;
} else {
// 如果 warehouses[index] 不存在,则创建它
this.$set(this.warehouses, index, {
value: item.WareHouseId,
label: item.Name,
children: []
});
}
});
}).catch(error => {
// 处理请求错误
});
一定要保证他不会进到true里面,不然还是会报错没有定义
this.http.post("", params, true).then(result => {
result.rows.forEach((item, index) => {
if (this.warehouses[indexArr] && this.warehouses[indexArr].children && this.warehouses[indexArr].children[index]) {
this.warehouses[indexArr].children[index].value = item.WareHouseId;
this.warehouses[indexArr].children[index].label = item.Name;
} else {
this.$set(this.warehouses[indexArr].children, index, {
value: item.WareHouseId,
label: item.Name,
// children: []
});
}
});
});