jeudi 26 janvier 2017

How to add condition in method vue.js 2?

My code is like this :

<template>
    <a href="javascript:" class="btn btn-block btn-success" @click="addFavoriteStore($event)">
        <span class="fa fa-heart"></span>&nbsp;
    </a>
</template>

<script>
    export default{
        props:['idStore'],
        mounted(){
            this.checkFavoriteStore()
        }, 
        methods:{
            addFavoriteStore(event){
                event.target.disabled = true
                const payload= {id_store: this.idStore}

                // if the labal = unfavorite
                if(unfavorite)
                    this.$store.dispatch('addFavoriteStore', payload)
                // if the label = favorite
                else
                    this.$store.dispatch('deleteFavoriteStore', payload)

                setTimeout(function () {
                    location.reload(true)
                }, 1500);
            },
            checkFavoriteStore(){
                const payload= {id_store: this.idStore}
                this.$store.dispatch('checkFavoriteStore', payload)
                // get response 
            }
        },
        data: {
            store_id: ''
        }
    }
</script>

I make the conditions as described above

You can look at the method addFavoriteStore

Whether that step is correct?

And how to determine it was favorite label or not to create conditions?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k6iUa2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire