http.api.aopeng.js
1.0 KB
//
let ApIndexUrl = '/ap/index.php';
// 此处第二个参数vm,就是我们在页面使用的this,你可以通过vm获取vuex等操作,更多内容详见uView对拦截器的介绍部分:
const install = (Vue, vm) => {
let getApIndexUrlApi = (params = {}) => vm.$u.get(ApIndexUrl, params).then(res => {
if (res.code >= 300 || res.code < 0) {
uni.$u.toast(res.msg);
} else {
return res.data
}
});
let postApIndexUrlApi = (ctl, met, params = {}) => vm.$u.post(ApIndexUrl+'?ctl='+ctl+'&met='+met, params).then(res => {
// let postApIndexUrlApi = (params = {}) => vm.$u.post(ApIndexUrl, params).then(res => {
if (res.code >= 300 || res.code < 0) {
uni.$u.toast(res.msg);
} else {
return res.data
}
});
// console.log('123123123123',vm.$u.api)
let api = {
getApIndexUrlApi,
postApIndexUrlApi
}
// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
vm.$u.api = {...vm.$u.api, ...api}
}
export default {
install
}