Javascript 重置星级组件VUE JS
我在vue js中使用明星评级插件,我使用v-model显示db的评级。一切正常,因为当用户未登录,他/她试图对其进行评级时,会显示错误“登录到评级”,但星星不会重置为db值,而是显示未登录用户的评级。当前在错误消息之后,我正在刷新整个页面。有没有一种简单的方法来重置星星而不是刷新整个页面Javascript 重置星级组件VUE JS,javascript,vuejs2,Javascript,Vuejs2,我在vue js中使用明星评级插件,我使用v-model显示db的评级。一切正常,因为当用户未登录,他/她试图对其进行评级时,会显示错误“登录到评级”,但星星不会重置为db值,而是显示未登录用户的评级。当前在错误消息之后,我正在刷新整个页面。有没有一种简单的方法来重置星星而不是刷新整个页面 :show-rating="false" @rating-selected="setRating" v-model="rating" v-bind:star
:show-rating="false" @rating-selected="setRating" v-model="rating"
v-bind:star-size="20"
上面是开始评级,单击它调用一个函数,我在其中检查用户是否使用api调用登录。提前谢谢
setRating: function (rating) {
axios.get('/checkuser').then(response => {
this.user = response.data;
if (this.user === "Logout") {
toastr.error('Please login to rate', 'Error', {
positionClass: 'toast-bottom-right'
});
window.location = "/menu/" + this.menu_id;
} else {
// save in to db
}
}).catch(error => {
// TODO: Handle error
});
},
如果对象未登录,则必须重置该对象
setRating: function (rating) {
axios.get('/checkuser').then(response => {
...
if (this.user === "Logout") {
...
this.rating = 0; <=== reset rating here (in data, not the rating parameter)
}
...
})
...
},
setRating:功能(额定值){
get('/checkuser')。然后(响应=>{
...
如果(this.user==“注销”){
...
this.rating=0;在api调用后使用“this.load()”修复了它,该调用刷新了所有组件。是否检查了添加的答案?感谢您的回复,我使用“this.load()”修复了它在api调用之后,刷新所有组件。:@HashaamAhmed可以,但是我想如果你只是为了评级而这样做的话,你应该避免load
。哦,为什么会这样?请解释一下,在vue js中我是新的:)@HashaamAhmed就像你提到的“刷新所有组件”这意味着每个组件都会有额外的渲染周期,尽管你只想刷新评级。好的,谢谢。我会看看是否真的会因此影响我的页面。加载:)