Axios拦截器- ReferenceError:数据未定义

omvjsjqw  于 11个月前  发布在  iOS
关注(0)|答案(1)|浏览(132)

我在Axios上遵循布拉德·特拉普的课程,我刚到拦截器。我遵循他写的,但我得到一个错误说:

ReferenceError: Data is not defined
    <anonymous> http://localhost:63342/Asynchronous JS/axios-notes/main.js:87
    promise callback*r.prototype.request https://unpkg.com/axios/dist/axios.min.js:2
    e https://unpkg.com/axios/dist/axios.min.js:2
    exports https://unpkg.com/axios/dist/axios.min.js:2
    getTodos http://localhost:63342/Asynchronous JS/axios-notes/main.js:14
    EventListener.handleEvent* http://localhost:63342/Asynchronous JS/axios-notes/main.js:134

字符串
这是我的拦截器代码:

axios.interceptors.request.use(
    config => {
        console.log(`${config.method.toUpperCase()} request sent to ${config.url} at ${new Data().getTime()}`);
        return config;
    },
    error => {
        return Promise.reject(error);
    }
);


一旦我删除这段代码并执行get/post请求,一切又都正常了,这意味着这段代码有问题。

jyztefdp

jyztefdp1#

请检查此行的日期对象是否正确,是new Date(),而不是new Data()

console.log(`${config.method.toUpperCase()} request sent to ${config.url} at ${new Data().getTime()}`);

字符串
将其校正成

console.log(`${config.method.toUpperCase()} request sent to ${config.url} at ${new Date().getTime()}`);

相关问题