常用的三种header中的三种content-type如下
1、Content-Type: application/json
2、Content-Type: multipart/form-data
3、Content-Type: application/x-www-form-urlencoded
项目中第二次遇到需要独立设置header中的content-type,故查阅而记之
1、Content-Type: application/json
import axios from 'axios' let data = {"code":"1234","name":"yyyy"}; axios.post(`${this.$url}/test/testRequest`,data) .then(res=>{ console.log('res=>',res); })
2、Content-Type: multipart/form-data
import axios from 'axios' let data = new FormData(); data.append('code','1234'); data.append('name','yyyy'); axios.post(`${this.$url}/test/testRequest`,data) .then(res=>{ console.log('res=>',res); })
3、Content-Type: application/x-www-form-urlencoded
import axios from 'axios' import qs from 'Qs' let data = {"code":"1234","name":"yyyy"}; axios.post(`${this.$url}/test/testRequest`,qs.stringify({ data })) .then(res=>{ console.log('res=>',res); })
axios修改content-type
axios.post(url, params, { headers: { 'Content-type':'application/x-www-form-urlencoded' } })