新建request.js
import cfg from "@/comm/cfg.js"
const get=(path,data=null,headers=null)=>{
return new Promise((resolve,reject)=>{
uni.request({
method:'GET',
url:cfg.baseUrl+path,
data: data,
header:headers
}).then(res=>{
resolve(res[1].data);
}).catch(err=>{
reject(err[1])
})
});
}
const post = function () {
return new Date().getTime();
};
const put=function(){
}
const dele=function(){
}
export default {get,post,put,dele}
main.js
import request from "utils/request.js"
Vue.prototype.$req = request
使用
this.$req.get({"/xxx/xxx/xxx",{"id":1}}).then((res)=>{
console.log(res)
}).catch((error)=>{
console.log(error)
})