vue-awesome-swiper icon indicating copy to clipboard operation
vue-awesome-swiper copied to clipboard

Cannot read property '$swiper' of undefined

Open solumon opened this issue 5 years ago • 9 comments

code:

import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
<swiper ref="mySwiper">
......
</swiper>
computed: {
      swiper () {
        return this.$refs.mySwiper.$swiper
      }
},
activated () {
      this.swiper.slideNext(1000)
}

error:

vue.esm.js?65d7:628 [Vue warn]: Error in activated hook: "TypeError: Cannot read property '$swiper' of undefined"

According to the official instructions configuration, do not know why can not find

solumon avatar May 23 '20 04:05 solumon

beacuse of different version, when i use v3.1.3, it's swiper, when i use v4.1.1, it's $swiper

Web-Li avatar Jun 11 '20 03:06 Web-Li

Getting the same error in 4.1.1. Have tried .swiper and .$swiper with no luck

frontendjordan avatar Jun 23 '20 21:06 frontendjordan

Is there any solution ? I got same error. I m using nuxt js. image

Swiper version : "vue-awesome-swiper": "^4.1.1",

fahim525 avatar Jul 22 '20 11:07 fahim525

Any update on this?

KevKashou avatar Sep 02 '20 00:09 KevKashou

+1

getr00t avatar Jun 16 '21 05:06 getr00t

Is there any solution ? I got same error. I m using nuxt js. image

Swiper version : "vue-awesome-swiper": "^4.1.1",

It’s not a bug. $swiper instance appears on “mounted” hook, but “computed” calculates some early. Also using $refs in computed is not good idea, cause it’s not reactive var, so computed going not to recalc after $swiper instance change.

Use something like mounted () { this.swiperInstance = this.$swiper }

igolka97 avatar Jul 04 '21 09:07 igolka97

现在解决了吗?

javaLuo avatar Jul 08 '21 04:07 javaLuo

现在解决了吗?

要指定下载对应的版本,swiper5.x,另外vue-awesome-swiper4.x,应该就好了,不然问题一堆,感觉吧swiper不友好,很多莫名的bug,居然还没有vue2.x的swiper对应教程demo,研究起来累。

getr00t avatar Jul 08 '21 11:07 getr00t

现在解决了吗?

要指定下载对应的版本,swiper5.x,另外vue-awesome-swiper4.x,应该就好了,不然问题一堆,感觉吧swiper不友好,很多莫名的bug,居然还没有vue2.x的swiper对应教程demo,研究起来累。 我发现了,不能写在v-if里 只要外面任何一层套了v-if, 就拿不到$swiper

javaLuo avatar Jul 08 '21 13:07 javaLuo