[英]read json from local file returned html?
I'm not sure what's wrong when my data.json return strange text when I call it. 我不确定data.json调用时返回奇怪文本时出了什么问题。
axios.get('./data.json').then(resp => {
console.log(resp)
console.log(resp.data)
})
Tried JSON.parse(resp) it doesn't seem to work. 尝试JSON.parse(resp)似乎不起作用。
https://codesandbox.io/s/306ynznkk5 https://codesandbox.io/s/306ynznkk5
You dont need axios to get data from json file. 您不需要axios从json文件获取数据。 axios is a library to make XHR request to server.
axios是一个向服务器发出XHR请求的库。 of course "./data.json" is not a url.
当然“ ./data.json”不是URL。 Then output from your function is text not found.
然后从您的函数输出是找不到文本。
import React from 'react';
...
import data from './data.json';
and try to console.log(data);
并尝试
console.log(data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.