axios不是函数错误,如何解决?

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

我正在尝试解决这个问题,但失败了。请帮助我:

enter image description here

  • 我尝试使用“npm install axios”重新安装,但没有成功。

  • 将 axios 版本更改为 1.1.2(以某种方式返回到 1.6.7)

  • 使用:const axios = require("axios").default

    const sendFile = async () => {
    if (image) {
      let formData = new FormData();
      formData.append("file", selectedFile);
      let res = await axios({    ## here I am getting the error
        method: "post",
        url: process.env.REACT_APP_API_URL,
        data: formData,
      });
      if (res.status === 200) {
        setData(res.data);
      }
      setIsloading(false);
    }
    }
    
reactjs axios
2个回答
0
投票

您的 import 语句在 ES6 语法中似乎是正确的。此错误通常是由于 axios 未正确初始化而发生。尝试清除node.js缓存并再次运行应用程序。

npm cache clean --force

您可以发布您的代码片段以供更多理解。


0
投票

您可以使用

let res = await axios.post({    ## here I am getting the error
    url: process.env.REACT_APP_API_URL,
    data: formData,
  });
© www.soinside.com 2019 - 2024. All rights reserved.