直接上代碼
api 接口封裝
export function userTypeObj(obj,callback) {
// obj 表示你的參數集合
// 返回的接口草callback裏邊
return request({
method:"PUT",
url:"接口地址",
data:obj,
transformRequest: [function (data) {
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret;
}],
headers:{
'Content-Type': 'application/x-www-form-urlencoded'
},
}).then((res)=>{
callback && callback(res.data);
});
}
請求方式
userTypeObj({name:"test",age:"15"}).then(data => {
// data 就是你請求到的數據
}).catch(() => {
});