“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
相关推荐
踏着七彩祥云的小丑7 小时前
pytest——Mark标记
开发语言·python·pytest
Dream of maid7 小时前
Python12(网络编程)
开发语言·网络·php
小李子呢02117 小时前
前端八股CSS(2)---动画的实现方式
前端·javascript
W23035765738 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
Y4090018 小时前
【多线程】线程安全(1)
java·开发语言·jvm
不爱吃炸鸡柳8 小时前
Python入门第一课:零基础认识Python + 环境搭建 + 基础语法精讲
开发语言·python
minji...8 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
Dxy12393102169 小时前
Python基于BERT的上下文纠错详解
开发语言·python·bert