引用LinUI编写微信小程序调用接口
Util.js
//获取缓存
static getStorageSync(key){
const res = wx.getStorageSync(key);
if (!res){
return false;
}
return res;
}
}
export {
Util
}
Http.js
import {Util} from "./Util";
import {promisic} from "../miniprogram_npm/lin-ui/utils/util";
class Http {
//调用接口
static async request(param) {
const token = Util.getStorageSync('token');
const data = await promisic(wx.request)({
url: 自己的url,
data: param.data,
method: param.method || "GET",
header: {
"token": token || ""
},
});
return data.data;
}
}
export {
Http
}
调用实例
**引入文件**
import {Http} from "./Http.js";
const data ={
要传的参数
“字段名”:值
}
GET请求方式
const res = await Http.request({
"url": "api/code",
data
});
console.log(res)
POST请求
const res = await Http.request({
"url": "api/code",
data,
"method":"post"
});
console.log(res)
链接: LinUI 框架.