const url_all = { 'DEV': 'http://XXX.XXX.XX.XX', // 此次存放baseUrl } let BASE_URL = url_all['DEV'] // let BASE_URL = url_all['_DEV'] export const request = (options = {}) => { const token = uni.getStorageSync('token') if(!token&&options.url!=='/login') { return uni.navigateTo({ url: '/pages/login/login' }) } return new Promise((resolve, reject) => { // 发送请求 uni.request({ url: BASE_URL + options.url || '', //接收请求的API header: { Authorization: token }, method: options.method || 'GET', //接收请求的方式,如果不传默认为GET data: options.data || {}, //接收请求的data,不传默认为空 }).then(data => { let [err, res] = data; resolve(res); }).catch(error => { reject(error); }) }) }