我有这样的数据:
逻辑
- 返回的数据包含名为
links
的子数据(数组) - 每个链接都有名为
closures
的子链接 - 我需要立即返回这些
闭包
作为数组。
代码
axios.post('/api/valChanger', {[val]: e})
.then(res => {
this.closures = res.data.data.links.closures;
})
.catch(error => {
//...
});
有什么想法吗?
最佳答案
在这种情况下使用剩余运算符:
axios.post('/api/valChanger', {[val]: e})
.then(res => {
let links = res.data.links;
for(let i = 0; i < links.length; i++){
this.closures = [...this.closures, ...links[i].closures]
}
})
.catch(error => {
//...
});
关于javascript - Vuejs 将数组子级合并为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61586004/