你在生命周期的哪个阶段获取的对象,贴代码
name: "Download",
data() {
return {
changeActive:0,
swiperOption: {
loop: true,
autoHeight: true,
pagination:{
el:'.nav',
type:'custom',
},
on:{
init:()=>{
},
slideChange:()=>{
console.log(this.swiper)
},
onSlideChangeEnd:()=>{
}
}
}
}
},
watch:{
},
methods: {
changeSwiper(item){
this.swiper.slideTo(item+1,1000,false);
this.changeActive=item;
},
// test(){
//
// }
},
computed: {
swiper() {
return this.$refs.mySwiper.swiper
}
},
mounted() {
console.log(this.swiper);
},
components: {
swiper,
swiperSlide
}
我也遇到了这个问题,
@wenguangcheng
@wenguangcheng @surmon-china
我遇到一样的问题,下图是我的组件代码,给swiper组件设置了ref属性

下图是我的mounted钩子中的打印代码

然后下图是我在google的开发者工具面板中打印的内容,可以看到swiper属性存在,但是取到该属性时,出现未定义报错


我也遇到同样的问题,发现是以组件的方式引入就会报这个错误,改成全局引入后,解决了这个问题
能不能把解决方法弄上来呢?
上面的问题已经解决了 多谢leobaixinxin老哥的贴图 让我意识到了 问题再swiper方法下面,也就是通过refs.ref获取对象后需要再refs.ref.swiper里面使用swiper4的方法 下面贴图 ,灵光一现 哈哈 亲测OK

在吐槽一下 楼主应该把使用方法的方式说一下~ @somemethods = "callback" 。。。 太简单了 菜鸟瑟瑟发抖
Most helpful comment
我也遇到同样的问题,发现是以组件的方式引入就会报这个错误,改成全局引入后,解决了这个问题