我剛開始學習react
。截至目前,我正在給我的應用程序提供一些硬編碼數據,我希望它可以通過一些外部API來取代它,並相應地加載數據。這是我迄今爲止所做的。在reactjs中調用api
import axios from "axios";
class TodoStore extends EventEmitter{
constructor() {
super();
this.todos = [
{
id: 123,
text: "Go Shopping",
complete: false
},
{
id: 456,
text: "Pay Bills",
complete: false
}
];
}
getAll(){
return this.todos;
}
現在我想做的事就是我想要實現https://jsonplaceholder.typicode.com/todos
,在我todos
分配所有返回的結果。那麼,這樣做的正確方法是什麼?任何幫助將不勝感激。