![](/img/trans.png)
[英]I am creating a like and dislike button, but it toggles the like count for ALL posts on the page, instead of the post being liked
[英]VueJs Like Button Liked all the posts
我在 Laravel 中使用 VueJs 實際上我制作了一個 VueJS 組件,其中包含類似按鈕並將其附加到循環中,因此當我按下任何類似按鈕時它會出現在每個帖子的末尾它喜歡所有帖子我的 VueJS 是
Vue.component('like-button', {
props: ['userId', 'likes'],
data: function() {
return{
status: this.likes,
}
},
methods: {
likeButton(){
axios.post('/like/' + this.userId)
.then(response=>{
this.status = !this.status;
history.go(0);
})
.catch(errors =>{
if(errors.response.status === 401){
window.location = "/login";
}
})
}
},
computed: {
/**
* @return {string}
*/
Texts() {
return (this.status) ? 'UNLIKE' : 'LIKE';
}
},
template: '<button v-on:click="likeButton" class="btn" style=" width: 100%;
background-color: #1b1e21;color: white; border: none;"
v-text="Texts"></button> '
})
我的刀片組件是(注意:我正在使用該按鈕上的循環,因此它出現在每個帖子的底部)
<like-button user-id="{{ $user->id }}" likes="{{ $likes }}"></like-button>
我只想喜歡那個按鈕像我按下的按鈕的帖子
實際上,錯誤出現在'/like/' + this.userId
我正在使用 userId 而不是 Post Id 感謝@ChrisG 的幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.