vue 2.x 中axios 封装的get 和post方法
发布时间:2020-12-17 02:33:37 所属栏目:百科 来源:网络整理
导读:vue 2.x axios 封装的get 和post方法 { axios.get(url,{ params: data }).then((res) => { if (res) { //成功回调 resolve(res); } }).catch((error) => { reject(error); }) }) } Post(url,reject) => { axios.post(url,qs.stringify(data),{ headers: { 'C
vue 2.x axios 封装的get 和post方法 {
axios.get(url,{
params: data
}).then((res) => {
if (res) {
//成功回调
resolve(res);
}
}).catch((error) => {
reject(error);
})
})
}
Post(url,reject) => {
axios.post(url,qs.stringify(data),{
headers: {
'Content-Type': 'application/x-www-form-urlencoded','Accept': 'application/json'
}
}).then((res) => {
if (res) {
//成功回调
resolve(res);
}
}).catch((error) => {
reject(error);
})
})
}
}
postfile方法 {
//根据data对象生成FormData对象
var temp = new FormData();
for (var t in data) {
temp.append(t,data[t]);
}
axios.post(url,temp).then((res) => {
if (res) {
resolve(res.Data);
}
}).catch((error) => {
reject(error);
})
})
}
总结以上所述是小编给大家介绍的vue 2.x 中axios 封装的get 和post方法。编程之家 52php.cn 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |