【问题标题】:Reactjs and firebase ::net::ERR_CONNECTION_TIMED_OUTReactjs 和 firebase ::net::ERR_CONNECTION_TIMED_OUT
【发布时间】:2020-09-25 12:21:21
【问题描述】:

这是一个 react 项目,我收到以下错误,我为 Axios 创建了一个单独的文件夹,该文件的代码在下面给出,然后我导入它,

import axios from 'axios';

const instance = axios.create({
    baseURL: 'https://burger-builder-urro.firebaseio.com/'
});

export default instance;

下面是我要发布数据的另一个文件的代码:

    purchasecontinuedHandler= ()=>{
            // alert("You Continue");
    
            const order = {
                ingredients: this.state.ingredients,
                price: this.state.totalprice,
                customer : {
                    name: "Mubarra",
                    address: {
                        street: 'Teststreet 1',
                        zipcode: '9382',
                        country: 'pakistan'
                    },
                    email: 'mubarraajmal.uet@gmail.com'
                },
                deliveryMethod : 'fastest'
            }
            axios.post('/orders.json', order)
                .then(response => console.log(response))
                .catch(error => console.log(error));
        }

我真的不知道为什么会显示这个错误:

【问题讨论】:

    标签: reactjs firebase firebase-realtime-database react-redux


    【解决方案1】:

    您将 baseURL 与 axios Post 附加到哪里?我想你忘了附加那个?

    【讨论】:

    • 追加是什么意思?
    • 您已经导出了实例,但是您在发布时使用了哪里?你又用过 axios.post 了吗?不是instance.post?
    • 但我是这样导入的:: import axios from '../../axios-order';然后因此我使用了 axios.post!!
    • 哦,现在可以使用了,非常感谢先生。先生导入名称应该与组件名称相同??
    • 当你做一个默认的导出名称可以是任何,但如果你需要导出多个函数或类,名称应该相同!。对于这样的导出,您需要像 import { name } from 'location' 一样导入
    猜你喜欢
    • 2018-02-04
    • 1970-01-01
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    相关资源
    最近更新 更多