Unable to fetch data from local json file by axios

后端 未结 1 820

I am using axios library for fetching data from the local json file but when i make get request it gives me error 404 not found. Here is my file structure.

相关标签:
1条回答
  • 2021-01-18 11:59

    If you created this file structure using create-react-app command you have to add your json files into public folder. then change your axios path like bellow

     handleSubmit = (e)=>{
       e.preventDefault();
       var username=e.target.username.value;
       var password=e.target.password.value;
       axios.get('./data.json')
       .then((res)=>{
         console.log(res.data);
       }).catch((err)=>{
         console.log(err);
       })
    
    0 讨论(0)
提交回复
热议问题