【发布时间】:2021-12-29 19:07:52
【问题描述】:
我正在关注 youtube 教程,因此我可以将 spotify 的 api 与我的 react 应用程序一起使用。本教程从 2017 年 11 月开始,因此语法可能已更改。我完全复制了代码,但收到“缺少分号”。错误。谁能帮我?我尝试在整个代码中的不同位置添加分号,但并不能解决问题。
我的代码:
import './App.css';
function App() {
constructor(){
super();
const params = this.getHashParams();
const token = params.access_token;
if (token) {
spotifyApi.setAccessToken(token);
}
this.state = {
loggedIn: token ? true : false,
nowPlaying: { name: 'Not Checked', albumArt: '' }
}
};
getHashParams() {
var hashParams = {};
var e, r = /([^&;=]+)=?([^&;]*)/g,
q = window.location.hash.substring(1);
while ( e = r.exec(q)) {
hashParams[e[1]] = decodeURIComponent(e[2]);
}
return hashParams;
}
return (
<div className="App">
<a href='http://localhost:8888'>
<button>Login with Spotify</button>
</a>
<div> Now Playing: { this.state.nowPlaying.name } </div>
<div>
<img src={ this.state.nowPlaying.image } style={{ width: 100}}/>
</div>
</div>
);
}
export default App;
错误信息:
Failed to compile.
./src/App.js
SyntaxError: /Users/manuelfiestas/client/src/App.js: Missing semicolon. (4:15)
2 |
3 | function App() {
> 4 | constructor(){
| ^
5 | super();
6 | const params = this.getHashParams();
7 | const token = params.access_token;
【问题讨论】:
标签: reactjs api constructor spotify