我收到此错误:
Parsing error: Unexpected token, expected ,
我在网上搜索,但没有解决。我也没有在这里看到任何错误
constructor(props) {
super(props);
fetch('url', {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify(collection) // <-- Post parameters
})
.then((response) => response.text())
.then(leaders => {
console.log(leaders);
}
} <---- here it gives error
答案 0 :(得分:1)
fetch('url', {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify(collection), // <-- Post parameters
})
.then(response => response.text())
.then((leaders) => {
console.log(leaders);
}); // << here's your issue ... missing `)`
建议
使用async-await
语法更易读且易于调试async code