http_weapp
基于flyio封装,api的统一管理。 注意:源码中为uniApp的环境代码,微信小程序、wepy、mpvue、cml、taro的可以在http.js 修改下环境条件代码和公共请求地址;
安装使用
npm:
$ npm i http_weapp
yarn:
$ yarn add http_weapp
注意
要将下载到 node_modules 的 http_weapp 拷贝到项目的根目录或其他目录。
使用 http_weapp (拷贝到根目录或其他目录)
.main文件
import apis from './http_weapp/index.js'Vue.prototype.$apis = apis;
http_weapp/index.js
...const apiJSON = {moule1:{userTest1:'post|user/test1'},login:'get|login/:testId'}//const apiJSON = {// '模块名':{// '接口名1':'接口'// },// '接口名2':'接口'//}// 例子(以页面为模块)://const apiJSON = {// 首页模块// 'pages/home/index':{// '接口名1':'接口',// '接口名2':'接口'// },// 个人中心模块// 'pages/my/index':{// '接口名3':'接口'// },// 'login':'接口'//}//调用//uniapp 中,将$apis 挂在在vue原型中// this.$apis['接口名'](参数1,参数2)//Taro 中,将$apis 挂在在Taro中。注意:要在http.js 中将环境代码改为Taro 的环境代码// Taro.$apis['接口名'](参数1,参数2)... wepy,cml,mpvue 类似...
.vue文件
//get请求 参数 name=123this.$apis.login({name:'123'},{testId:111}) // => http://xxxx/login/111?name=123//post请求 参数 {name:123} 拼接参数{id:111}this.$apis.login({name:'123'},{testId:111}) // => http://xxxx/login/111//get请求 参数 空 拼接参数{id:111}this.$apis.login(null,{testId:111}) // => http://xxxx/login/111