[Vuejs]-How can I run slider in vue component?

0👍

Ok, try this.

<template>
   <div ref="slick">
      <div class="row">
        <div class="col-md-3" v-for="item in items">
             <div class="panel panel-default">
                <div class="panel-image">
                    <a :href="baseUrl+'/leagues/'+item.id+'/'+item.name"
                        :style="{backgroundImage: 'url(' + baseUrl + '/img/leagues/'+item.photo+ ')'}">
                    </a>
                </div>
            </div>
        </div>
    </div>
  </div>
</template>
<script>
    ...
    export default {
        ...
        props: ['leagueId'],
        mounted() {
            $(this.$el).slick({slidesToShow: 3, infinite: false});
            this.getTopLeague([{league_id: this.leagueId}]) // this is ajax if load first
        },
        computed: {
            ...mapGetters([
                'getListLeague'
            ]),
            items() {
                const n = ['getListLeague']
                return this[n[0]] // this is response ajax // exist 5 league
            }
        },
        methods: {
            ...mapActions([
                'getTopLeague'
            ]),
            changeLeague(leagueId) {
                this.getTopLeague([{league_id: leagueId}]) // this is ajax if a link clicked     
            }
        }
    }
</script>

Leave a comment