“TypeError: utils request jS WEBPACK IMPORTED MODULE O .default is undefined‘报错

写项目时报下列错误,找了半天,结果才发现自己在request.js中少写了一行代码

一定不要少些代码

javascript 复制代码
export default request

request.js完整代码

javascript 复制代码
import axios from 'axios';

//创建一个新的axios对象
const request  = axios.create({
    baseURL:'http://localhost:9988',
    timeout:30000
})

//request拦截器
//可以自请求发送前对请求做一些处理
//比如统一加token,对请求参数统一加密
request.interceptors.request.use(config => {
    config.headers['Content-Type'] = 'application/json;charset=utf-8';
    //let user = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) :null
    //config.headers['token'] = user ?.token ;//设置请求头

    return config
}, error => {
    console.error('request error:'+ error) //for debug
    return Promise.reject(error)
});

//response拦截器
//可以在接口响应后统一处理结果

request.interceptors.response.use(
    response => {
        let res = response.data;

        //兼容服务端返回的字符串数据
        if (typeof res === 'string') {
            res = res ? JSON.parse(res) : res
        }
        return res;
    },
    error => {
        console.error('response error: ' + error) //for debug
        return Promise.reject(error)
    }
)
export default request
相关推荐
大可不必了15 小时前
03 函数定义和调用
开发语言·python
I_belong_to_jesus15 小时前
C++关于分支预测的优化1
开发语言·c++·算法
承渊政道16 小时前
【Python编程—从入门到实践】(记分与闯关:用Python+Pygame,打造越战越精彩的太空大战!)
开发语言·python·pycharm·游戏程序·pygame
爱学习的程序媛16 小时前
Python常用框架梳理
开发语言·后端·python·ai·web·后端框架·python框架
eggwyw17 小时前
Anaconda安装卸载的详细流程指南
开发语言·python
用户00447295382518 小时前
练歌镜:让眼镜听懂“循环这一句”
javascript
yuyuxun121 小时前
协同过滤的校园二手物品智能推荐系统的设计与实现 毕业设计-附源码40082
javascript·vue.js·spring boot·python·数据分析·django·课程设计
another heaven1 天前
【C/C++ Ranges 是零开销抽象吗?拆开管道、惰性求值和编译期膨胀】
c语言·开发语言·c++
SomeOtherTime1 天前
Rust 闭包语法和原理(AI回答)
开发语言·后端·rust
apcipot_rain1 天前
C++转Java日记(10)
java·开发语言