我有一个这样的箱子
首先我从服务器获取数据,然后响应是
{
data: {
id: 4,
status: A,
items: {
child: [
{
id: 28,
product_id: 1
},
{
id: 33,
product_id: 4
}
]
}
},
status: 200,
error: 0
}
在那之后,我想把数组items.child作为post中的参数发送。
下面是post中要设置的参数的格式:
item_id : data.id
item_status: data.status
item_combo_28_0: 1|0
item_combo_33_1: 4|1
item_combo是从响应数据获取的动态参数
注意:item_combo_u(child.id)_index:child.product_124;id|索引
这里是我的AXIOS代码
getData() {
let headers = {
Authorization: 'Bearer ' + window.accessToken
}
let id = val
axios({
method: 'GET',
url: BASE_API('productcombo/' + id),
headers: headers
})
.then(response => {
this.itemCombo = []
this.dataResponse = response.data.data
this.setItemPackage()
this.loading = false
})
.catch(error => {
this.loading = false
})
},
setItemPackage() {
if (this.dataResponse.items.child.length > 0) {
this.dataResponse.items.child.map((row, idx) => {
this.$set(row, 'item_combo_' + row.id + '_' + [idx], row.product_id + '|' + idx)
this.itemCombo.push(row)
console.log(this.itemCombo)
})
}
}
应输入:如何为(item_combo_2;?)设置post的动态参数
这是我的邮政编码
sendData() {
this.loadingPackage = true
let headers = {
Authorization: 'Bearer ' + window.accessToken
}
let data = {
item_id: this.dataResponse.id,
item_tatus: this.dataResponse.status,
======= Here my expect =========
item_combo_27_0: 13 | 0,
item_combo_3_1: 15 | 0
================================
}
axios({
method: 'POST',
url: BASE_API('openorder/additemcombo'),
headers: headers,
data: data
})
.then(response => {
this.result = response.data
}
if (response.data.error) {
this.$message({
message: 'Error Network',
type: 'error'
})
}
})
.catch(() => {
this.$notify({
message: 'Error Connections',
type: 'warning'
})
})
},