【发布时间】:2018-11-06 14:29:33
【问题描述】:
你能帮帮我吗? 我有带有 body 参数的 POST 方法,var product_ids 中有两个值
BODY
product_ids = 8|559
customer_type_id = 2
qty_from = 11
sell_price = 10001
这是我的 axios 代码
createNewPricetiers() {
this.loading = true
let headers = {
Authorization: 'Bearer ' + window.accessToken
}
let data = {
product_ids: this.$route.params.id || this.form.variant,
customer_type_id: this.form.customer,
qty_from: this.form.qty,
sell_price: this.form.sellPrice
}
axios({
method: 'POST',
url: BASE_API + 'productpricetiers',
headers: headers,
data: data
})
...
但是当它调用服务器时,多个参数不能运行
只需发送参数this.$route.params.id
我的错在哪里?
【问题讨论】:
-
你的意思是
product_ids: `${this.$route.params.id}|${this.form.variant}`吗?||是布尔“或”运算符 -
是的,我知道,但是 product_ids 中正文的后端请求是带分隔符的两个值
-
这就是我从问题顶部的示例中得出的结论。那么,你尝试过我的建议了吗?如果您不喜欢字符串模板文字,也可以使用
product_ids: this.$route.params.id + '|' + this.form.variant。甚至[this.$route.params.id, this.form.variant].join('|')。结果是一样的 -
投票结束是一个错字。您应该创建一个以竖线分隔的字符串,而不是布尔表达式
-
太棒了,谢谢@phil。但是您都建议它是字符串值而不是整数?