import { config } from '@/config/config'; //引入公用文件 export const Request = options => { return new Promise((resolve, reject) => { const token = uni.getStorageSync('token'); const TokenType = uni.getStorageSync('TokenType'); uni.request({ url: config.host + options.url, //接口地址:前缀+方法中传入的地址 method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET” data: options.data || {}, //传递参数:传入的参数或者默认传递空集合 header: { Authorization: `${TokenType || 'Bearer'} ${token || ''}`, 'Content-Type': 'application/json;charset=utf-8' }, success: function(res) { if (res.statusCode == 401) { console.log('跳转'); uni.navigateTo({url:'/pages/login/login'}) } else { resolve(res.data); } }, fail: err => { uni.showToast({ title: '请求失败,请刷新', duration: 2000, icon: 'none' }); reject(err); } }); }); };