配置文件:
import axios from 'axios'
import qs from 'qs'
import * as _ from './whole'
axios.defaults.timeout = 5000;
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
axios.defaults.baseURL = 'http://www.guinaben.com:8070';
// axios.defaults.baseURL = 'http://192.168.1.129:8383';
//POST传参序列化
axios.interceptors.request.use((config) => {
if(config.method === 'post'){
config.data = qs.stringify(config.data);
}
return config;
},(error) =>{
_.toast("错误的传参");
return Promise.reject(error);
});
//code状态码200判断
axios.interceptors.response.use((res) =>{
if(res.data.code != '200'){
_.toast(res.data.msg);
return Promise.reject(res);
}
return res;
}, (error) => {
_.toast("网络异常");
return Promise.reject(error);
});
export default axios;
请求:
import axios from 'config/http'
axios({
method:'get',
url: 'xxxx/xxxxx',
params: {
"textbook_id":id,
"token":token
}
})
.then((response) => {
resolve(response);
})
axios({
method:'post',
url: 'teacher/pwd/resetByMobile',
data: {
"textbook_id":id,
"token":token
}
})
.then((response) => {
resolve(response);
})
网友评论