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

问题描述 投票:0回答:1

我正在学习 Brad Traversy 在 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 请求,一切都会再次工作,这意味着这段代码有问题。

javascript axios frontend referenceerror
1个回答
0
投票

请检查此行中日期的正确对象是

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()}`);
© www.soinside.com 2019 - 2024. All rights reserved.