A post request

  1. The parameter is transmitted through string concatenation
this.axios.post(`https://.... /updateAddress? addressName=${this.addressName}&houseNumber=${this.houseNumber}&userName=${this.userName}&userPhone=${this.userPhone}&isdefault=${this.isDefault}&addressId=${this.addressId}`)
            .then(response => {
                //...
            })
Copy the code
  1. The JSON object submits data
let data = {
        'user': { 'id': `${this.$user.getUserId()}`},'hideFlag': '1'.'content': this.content,
        'pictureUrl': this.imgUrl
      }
      this.axios.post('https://..... /submitFeedback', data)
        .then(this.postFeedBackSucc)
        .catch((e) => {
          console.log(e)
        })
Copy the code

  • Example 1: JSON object string passing data (I don’t know what I’m talking about, the back end wants a JSON object to store the data to be passed, but this json object is converted to string)
let data = new FormData()
      data.append('json', JSON.stringify({ 'userId': `45435465464` }))
      this.axios.post('https://houqin.eooker.com/delivery/a/shop/merchantAPI/markList', data, {
        header: {
          'Content-Type': 'multipart/form-data'
        }
      })
        .then(response => {
            //.....
        })
        .catch((e) => {
          console.log(e)
        })
Copy the code

  • Example 2: Pass data in form form via key-value pairs
var formData=new FormData();
formData.append('user', 123456); formData.append('pass', 12345678); axios.post("/notice",formData)
     .then((res) => {return res})
     .catch((err) => {return err})
Copy the code

A get request

  1. String concatenation (not recommended)
_self.axios.get(`https://..... /pay? orderNumber=${_self.orderNumber}&openId=${_self.$user.getOpenId()}`).then(result => {
        //.....
      }).catch(err => {
        console.log(err)
      })
Copy the code



Params parameter must be written, if no parameter is passed {} can also be used

 let data = { userId: this.$user.getUserId(), start: 0, size: 10 }
    this.axios.get('https://.... /listByUserId', { params: { 'json': data } })
    .then(response => {
        //.....
    })
    .catch((e) => {
        console.log(e)
    })
Copy the code