【发布时间】:2017-06-12 10:51:08
【问题描述】:
我的代码是这样的:
<template>
<a href="javascript:" class="btn btn-block btn-success" @click="addFavoriteStore($event)">
<span class="fa fa-heart"></span> <label id="favoriteId">{{ store_id == $store->id ? '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}
this.$store.dispatch('checkFavoriteStore', payload)
// this is response. return store_id
}
},
data: {
store_id: ''
}
}
</script>
我按照上述条件提出
你可以看看方法addFavoriteStore
那一步是否正确?
以及如何判断是不是喜欢标签创造条件?
更新
在控制台中存在这样的错误:
[Vue warn]: The "data" option should be a function that returns a per-instance value in component definitions.
【问题讨论】:
-
您遇到或尝试了哪些错误,您能再解释一下吗?另外
event.target.disabled = true为什么不在点击方法@click.prevent=""vuejs.org/v2/guide/events.html上添加prevent调用:-) -
你的问题不是很清楚,请考虑改进一下。你想达到什么目的?真正的问题在哪里?
-
@Simon Davies,我更新了我的问题
-
@Belmin Bedak,我更新了我的问题
标签: javascript laravel-5 vue.js laravel-5.3 vuejs2