uni封装请求
使用uniapp发送请求时,要用到自身的API,uni.request
可以将其封装在index文件里,后面使用的时候也更加方便
const BASE_URL = 'https://localhost:8081/api'; export const $req = (option) => { return new Promise((resolve, reject) => { uni.request({ url: BASE_URL+option.url, method:option.method || 'GET', data: option.data || {}, success: res =>{ if(res.data.meta.status !== 200){ return uni.showToast({ title:'失败' }) } resolve(res) }, fail:(error)=>{ return uni.showToast({ title:'失败' }) reject(error) } }) }) }

浙公网安备 33010602011771号