VueJs - Axios:如何在params中发送多个值?

时间:2018-05-28 03:47:25

标签: vuejs2 axios

你能帮帮我吗? 我有一个带有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 我的错在哪里?

1 个答案:

答案 0 :(得分:0)

使用axios.post时添加默认标头:

import axios from 'axios';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';