接口请求成功,但是不执行.then和.catch,求大佬解惑

2023-12-24 23:25:58

const BASE_URL = 'https://brain.zjhyai.com/chat/'
import axios from "axios";
const request = ({
                     url,
                     data = {},
                     method = 'get',
                     header = {
                         ContentType: 'application/json'
                     },
                 }) => {
    let token = localStorage.getItem('token') || '';
    if (!url) return;
    return new Promise((resolve, reject) => {
        axios({
            url: BASE_URL + url,
            method,
            data,
            header: {
                token,
                ...header
            },
            success: (res) => {
                console.log(res)
                if (res.statusCode === 200 && res.data.msg === 'success') {
                  return resolve(res.data)
                } else if (res.statusCode === 403) {
                    this.$notify.error({
                        title: '错误',
                        message: res.data
                    });

                } else if (res.data.code === 8000) {
                    this.$router.push({path:'/'})
                    // #endif
                    // #ifdef H5
                    let ua = navigator.userAgent.toLowerCase();
                    if (ua.match(/MicroMessenger/i) == "micromessenger") {
                        //是
                        this.$router.push({path:'/'})

                    } else {
                        //不是
                        this.$router.push({path:'/'})

                    }
                    this.$router.push({path:'/'})


                } else {
                    this.$notify.error({
                        title: '错误',
                        message: res.data.msg
                    });
                }
            },
            fail: (err) => {
                reject(err);
            }
        });
    })
}

export default request;

文章来源:https://blog.csdn.net/m0_72815229/article/details/135184623
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。