uniapp关于请求的封装
// const baseURL = "https://xxx"; const baseURL = "https://xxx"; export default function(params) { const { url, data = {}, method = "GET" } = params; console.log(method, "method"); const token = uni.getStorageSync("token"); const fullURL = baseURL + url; return new Promise((resolve, reject) => { uni.request({ url: fullURL, data, method: method.toUpperCase(), header: { Authorization: token || "", }, timeout: 10000, success: (res) => { resolve(res.data); }, fail: (err) => { reject(err); }, }); }); }
外部使用当前文件
import http from '当前文件路径'
本想把生活活成一首诗, 时而优雅 , 时而豪放 , 结果活成了一首歌 , 时而不靠谱 , 时而不着调