解析错误:意外的令牌,预期的,

时间:2019-03-27 10:44:53

标签: react-native

我收到此错误: 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

1 个答案:

答案 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