Home  >  Q&A  >  body text

javascript - Using axios to request a local json file in vue2.0, the result is a 404 error. I have tried many methods and still get the error. Beginners, please give me some advice.

This is the vue page

This is the project structure

result

The configuration added by index.js under config

The modified path in the axios configuration file

Everything is wrong no matter how I set the path. I just can’t find this json file. I hope someone can give me some advice. Thank you

我想大声告诉你我想大声告诉你2710 days ago1710

reply all(5)I'll reply

  • 迷茫

    迷茫2017-05-19 10:33:07

    Put the home.json file in the /static/ directory, and then

    axios.get('http://localhost:8080/static/home.json')

    reply
    0
  • 某草草

    某草草2017-05-19 10:33:07

    Just fill in the domain name for target in proxy. Come and thank me

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-19 10:33:07

    你这是访问服务器文件,应该把json文件放在最外层的static文件夹,这个文件夹是vue-cli内置服务器向外暴露的静态文件夹

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:33:07

    It seems that axios requests http, so the json file I created myself cannot be accessed? I don’t understand a bit

    reply
    0
  • 为情所困

    为情所困2017-05-19 10:33:07

    Modify the local dev-server.js... just parse it into static resources...

    For example, put your json in the /example folder and modify express as follows~

    build/dev-server.js

    app.use('/example', express.static('./example'))

    reply
    0
  • Cancelreply