** 在network文件夹里的core文件 添加**
headers:{'Content-Type':'application/x-www-form-urlencoded'},
transformRequest:[function (data) {
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}]
模板样式:
import {GET,POST} from "./config" // 从config.js 接受GET 和POST 的请求
import axios from "axios"; //再接受axios
let instance =axios.create({//axios本有的属性 创建
baseURL:"https://api.it120.cc", //baseURL:公共的url
timeout:10000 , //请求数据时超时时间
headers:{'Content-Type':'application/x-www-form-urlencoded'},
transformRequest:[function (data) {
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}]
})
export function request(method,url,params){
switch (method){
case GET:
return get(url ,params)
case POST:
return post(url , params)
}
}
function get (url ,params){
return instance.get(url , params)
}
function post (url ,params){
return instance .post (url ,params)
}