【发布时间】:2019-10-29 15:48:47
【问题描述】:
我想使用 fetch 从带有 react js 的虚拟 API 中获取结果。但我从 console.log()
收到“SyntaxError: Unexpected tokenhandleSubmit(event) {
fetch({
url:'http://dummy.restapiexample.com/api/v1/employees',
mode: 'cors',
method: 'GET',
dataType: 'json',
headers: {
'Access-Control-Allow-Origin':'*',
'Content-Type': 'multipart/form-data'
}
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error(error);
});
event.preventDefault();
}
【问题讨论】:
-
看起来不错!你能提供更多关于错误日志的描述吗?