axios post请求get请求对传参的操作

axios post请求get请求对传参的操作

  • 特别说明
    • axios get传参
    • axios post传参

特别说明

//以下都是基于
 headers: {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
  }

axios get传参

1.params传参:

		this.$http({
                url: '/api/xxx',
                method: 'get',
                params: {
                    customer_num:‘’
                }
            }).then(res => {
               // do something
            })

axios post传参

1.data transformRequest处理

	this.$http({
              url: '/api/xxx',
              method: 'post',
              data: {
              		name:''
              },
              transformRequest: [function (data) {
                let ret = ''
                for (let it in data) {
                  ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                }
                ret = ret.slice(0,-1)
                return ret
              }]
            }).then( (response) => {
                // do something
                
            })
  1. data qs处理
 npm i qs
//main.js里面
import qs from 'qs'
Vue.prototype.$qs = qs
//使用
this.$http({
                url: '/api/xxx',
                method: 'post',
                data: this.$qs.stringify(params)
            })

你可能感兴趣的:(axios post请求get请求对传参的操作)