Vue-carousel: How can I get the current index?

Created on 22 Aug 2017  路  7Comments  路  Source: SSENSE/vue-carousel

How can I get the current index?
Can you add a function to return the current index?

Most helpful comment

In your template
<carousel v-on:pageChange="pageChange">...</carousel>
In your script
methods: { pageChange(i){ console.log('current Index', i); }, }

Note: It fired when you change current page (by navigation or pagination)

All 7 comments

Did you find out how to get or set the index?

 <carousel ref="carousel">
...
</carousel>


computed: {
      currentIndex: {
        cache: false,
        get() {
          return this.$refs.carousel ? this.$refs.carousel.currentPage : 0;
        }
      }
    }
  <carousel ref="carousel" :perPage="1" :perPageCustom="[[320,1],[480,1],[960,1]]" :paginationEnabled="false" :navigationEnabled="true" >
    <slide v-for="content in contens">
    ...
   </slide>
</carosel>
computed: {
   ...mapGetters({...}),
  currentIndex: {
        get () {
          return this.$refs.carousel ? this.$refs.carousel.currentPage : 0
        }
      }
}

Getting currentindex 0 for all slides

try to add;

cache: false
computed: {
   ...mapGetters({...}),
  currentIndex: {
        cache: false,
        get () {
          return this.$refs.carousel ? this.$refs.carousel.currentPage : 0
        }
      }
}

No luck :(
this.$refs.carousel is undefined

In your template
<carousel v-on:pageChange="pageChange">...</carousel>
In your script
methods: { pageChange(i){ console.log('current Index', i); }, }

Note: It fired when you change current page (by navigation or pagination)

@hhlingyoko, please, close this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SAL-MichaelZanggl picture SAL-MichaelZanggl  路  3Comments

kenyk7 picture kenyk7  路  4Comments

bepi-roggiuzza picture bepi-roggiuzza  路  4Comments

power-cut picture power-cut  路  5Comments

rizqirizqi picture rizqirizqi  路  5Comments