Vue-awesome-swiper: Cannot read property 'swiper' of undefined" when 'not-next-tick:true' in mounted

Created on 10 Aug 2017  ·  6Comments  ·  Source: surmon-china/vue-awesome-swiper

template:

<swiper :options="swiperOption" :not-next-tick="notNextTick" ref="mySwiper">
  <slide v-for="item in XXX">
</swiper

script:

data:{
       notNextTick: true,
        swiperOption: {
          initialSlide: 0,
          onlyExternal: true,
          onInit: (swiper) => {
            console.log(swiper)
          },
          onReachEnd: (swiper) => {
            console.log('last slide')
          }
        }
},
computed: {
      swiper () {
        return this.$refs.mySwiper.swiper
      }},
mounted () {
     console.log(this)
     console.log(this.swiper)
}

all above is my real code refered to README/#Use in SPA

error in broswer and never console
image
image

I need swiper instance first time,but I can't get it
Someone else know why and how?

Most helpful comment

The reason for the real mistake is that this swiper's parent has v-if, change v-if to v-show

All 6 comments

Format and refine your code.

I'm sorry, I did not get this error here, is it caused by other code?

@surmon-china Thank you,I also dont't know why it is. I can console the 'this' and find the swiper in 'this'. The close next console can't log the swiper. Key code as above. I am not sure the error caused by other.I will check my code more carefully to find the original error

The reason for the real mistake is that this context is incorrect, this is undefined, so no swiper object.

The reason for the real mistake is that this swiper's parent has v-if, change v-if to v-show

I am also facing the same issue, on initial load it is showing the swiperobject but once I route and come back to that same page, I do face that issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tilight picture tilight  ·  5Comments

zhaoFangyi picture zhaoFangyi  ·  7Comments

kooshkestani picture kooshkestani  ·  5Comments

pfasang picture pfasang  ·  5Comments

Ivan-blade picture Ivan-blade  ·  6Comments