u-axios
v0.0.4
Published
封装的uni.request 模仿axios并实现了一部分功能
Downloads
9
Readme
使用方法
import { BASE_URL } from "./config";
import Request from "./request/index";
const request = new Request();
const instance = request.create({
baseURL: BASE_URL,
timeout: 5000
});
instance.interceptors.request.use(config => {
console.log(config);
config.method = "post";
return config;
});
instance.interceptors.response.use(
res => {
return res.data;
},
err => {
return err;
}
);
export default instance;
import request from "@/utils/request.js";
function demo(data) {
return request({
url: "/",
header: { token: "token" },
abortSame: false,//判断是否需要中断上一个相同url相同method的连接
data: data,//无论是get还是post 都是data 这里和axios不一样
method: "post"
});
}
demo(data).then(res=>{
..........执行一些方法
}).catch(err=>{
..........执行一些方法
})