quanyawei
2023-10-27 52d463e03c1f074099ed8e8a6b7c3ddde52d2708
utils/request.js
@@ -1,4 +1,5 @@
import storage from './storage' // 缓存封装
import store from '../store/index.js'
export default {
    console(options) {
        if (config.debug) {
@@ -20,13 +21,14 @@
        // loading加载
        uni.showLoading({ title: '加载中', })
        // 拼接路劲,下面的配置文件会提到
        // uni.showLoading({ title: baseUrl, })
        options.url = baseUrl + '' + options.url
        // 请求方式
        options.method = options.method || 'GET'
        // 判断登录是否
        if (isLogin) {
            let token = storage.get('token')
            console.log('tokentoken', token)
            let token = uni.getStorageSync('tonken')
            console.log('token', token)
            if (token !== null) {
                // options.header["token"] = token;
                options.header = {
@@ -40,7 +42,7 @@
        return new Promise((resolve, reject) => {
            uni.request(options).then(data => {
                var [error, res] = data
                if (error != null) {
                if (error !== null) {
                    reject(error)
                } else {
                    // 相应拦截、根据后端的状态码来写,可以自行判断和封装