export const baseURL = 'https://cloud.long-chi.com/api' export const request = (options) => { return new Promise((resolve, reject) => { uni.request({ url: baseURL + options.url, //接口地址:前缀+方法中传入的地址 method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET” data: options.data || {}, //传递参数:传入的参数或者默认传递空集合 header: { 'Authorization': uni.getStorageSync("token") || "" //自定义请求头信息 }, success: (res) => { //返回的数据(不固定,看后端接口,这里是做了一个判断,如果不为true,用uni.showToast方法提示获取数据失败) if (res.data.code == 200) { resolve(res.data) } else { if(res.data.code== 401){ uni.navigateTo({ url:'/pages/login/login' }) } reject(res.data.msg) uni.showModal({ title:'提示', content:res.data.msg, showCancel:false }) } // 如果不满足上述判断就输出数据 }, // 这里的接口请求,如果出现问题就输出接口请求失败 fail: (err) => { console.log(err) reject(err) } }) }) } // import {getUserInfo} from '@/api/mine' // methods: { // async getUserInfo(){ // try { // const res = await getUserInfo() // this.userInfo = res // console.log('getUserInfo', res) // // 保存数据 // } catch (err) { // uni.showToast({ title:err,icon:'none' }) // console.log('getUserInfo', err) // } // }, // }