试试这个:
const data = require("../data/transportationDataCheck.json")
console.log(JSON.stringify(data));
或者您可以尝试更改一下URL后再试一次
let transportation = [];
const init = () => {
fetch('../data/transportationDataCheck.json')
.then((response) => {
return response.json();
})
.then((data) => {
transportation = data;
}).then(() => {
renderList(transportation);
});
};
var transportationDataCheck = require('./data/transportationDataCheck.json');```
fetch('./data/transportationDataCheck.json')
.then(response => {
return response.json()
})
.then(data => {
// Work with JSON data here
console.log(data)
})
.catch(err => {
// Do something for an error here
})
response.ok
以查看HTTP请求是否成功(不幸的是,“fetch”仅在网络错误而不是HTTP错误时拒绝)。