微信小程序网络请求封装
const baseUrl = "https://www.xxxxx.xxx/xxx"
let token = wx.getStorageSync('token')
const request = (options) => {
return new Promise((resolve,reject) => {
options.url = baseUrl + options.url
wx.request({
...options,
header: {
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Cookie':wx.getStorageSync('cookieKey'),
'token':`${token}`
},
success: function (res) {
console.log("network-res=>", res);
wx.setStorageSync("cookieKey", res.header["Set-Cookie"]);
resolve(res.data)
},
fail: function (error) {
console.log("network-err=>", error);
reject(error)
}
})
})
}
export default request
import request from './request.js'
export function getUserInfo(data) {
return request({
url: `/slides`,
method: 'GET',
data:data
})
}
import { getUserInfo } from "../../http/api.js";
async onLoad(options) {
let res = await getUserInfo()
},