【发布时间】:2017-06-13 18:03:11
【问题描述】:
我的看法是这样的:
<div class="favorite" style="margin-bottom:5px;">
@if (Auth::user())
<add-favorite-store :id-store="{{ $store->id }}"></add-favorite-store>
@else
<a href="javascript:" class="btn btn-block btn-success">
<span class="fa fa-heart"></span> Favorite
</a>
@endif
</div>
我的组件是这样的:
<template>
<a href="javascript:" class="btn btn-block btn-success" @click="addFavoriteStore($event)">
<span class="fa fa-heart"></span> <label id="favoriteId">{{ store_id == 'responseFound' ? 'Un-Favorite' : 'Favorite' }}</label>
</a>
</template>
<script>
export default{
props:['idStore'],
mounted(){
this.checkFavoriteStore()
},
methods:{
addFavoriteStore(event){
var label = $('#favoriteId')
var text = label.text()
event.target.disabled = true
const payload= {id_store: this.idStore}
if(text == "Favorite") {
this.$store.dispatch('addFavoriteStore', payload)
}
else {
this.$store.dispatch('deleteFavoriteStore', payload)
}
setTimeout(function () {
location.reload(true)
}, 1500)
},
checkFavoriteStore(){
const payload= {id_store: this.idStore}
var data = this.$store.dispatch('checkFavoriteStore', payload)
data.then((res) => this.store_id = res)
}
},
data() {
return {
store_id: ''
}
}
}
</script>
在我上面的代码中,我使用了
location.reload(true)
更新页面上的数据。但它正在重新加载页面。
我想要更新页面时,它不会重新加载页面
我该怎么做?
【问题讨论】:
-
您能否添加相关的html代码以便我们解决这个问题,您需要在VUE中查找绑定。还要说明您尝试更新的内容,以便我们也可以为您解决此问题。您不要刷新页面添加绑定变量,因此更新脚本中的 var 也会更新变量/html。
-
不是问题,但您能否解释一下您想要更新的内容,如用户执行此操作,然后执行此操作,然后我想执行此操作,说明过程和需要做什么发生了,你使用很多普通的 js 和 vue 可以代替你处理这个
标签: javascript laravel-5.3 vuejs2 vue.js