let obj = {
text: "",
value: "",
};
get("/api/common/dict/select", data)
.then((res) => {
if (res.code == 1) {
res.data.forEach((item, index) => {
obj.text = item.label;
obj.value = index;
this.$set(this.actions, index, obj);
});
} else if (res.code == 0) {
this.$toast(res.msg);
}
})
得到的数据全是最后一组的数组
解决方法
get("/api/common/dict/select", data)
.then((res) => {
if (res.code == 1) {
res.data.forEach((item, index) => {
let obj = {
text: "",
value: "",
};
obj.text = item.label;
obj.value = index;
this.$set(this.actions, index, obj);
});
} else if (res.code == 0) {
this.$toast(res.msg);
}
})
每次循环的时候,新建对象