這是我的代碼:如何使其成為專業人士?,對于這種情況,最好的 Laravel API 庫是什么?
likePost() {
fetch("api/like_post" , {
method: "POST",
headers: {
'Key': '11111111111111111'
}
})
}
uj5u.com熱心網友回復:
我想你可以看看這個很棒的 Laravel API 包:https : //github.com/ejarnutowski/laravel-api-key,
您可以通過以下語法使您的代碼更好:
首先為喜歡添加新狀態
this.state = {
likes: 0,
};
然后系結函式:
this.likePost = this.likePost.bind(this);
并像這樣創建最終函式:
likePost(post_id, user_id) {
fetch("api/like_post" , {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
'X-Authorization': 'KkKf87BOncnOGwzjLBG8Isd87T42D1yOJJNoUMsrjmUkqSIxXmHG4XPZ07UQM0Pi'
},
body: JSON.stringify({
"post_id": post_id,
"user_id": user_id
})
})
.then(res => res.json())
.then(likes => this.setState({likes:likes}))
.catch(error => {
// Log Error
console.log(error)
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/379617.html
