报错 'update' of undefined

报错 'update' of undefined

<template>

<swiper :options="swiperOption" ref="swiper">

<swiper-slide>

<slot></slot>

</swiper-slide>

<div class="swiper-scrollbar" v-if="scrollbar" slot="scrollbar"></div>

</swiper>

</template>

<script>

import {Swiper,SwiperSlide} from 'vue-awesome-swiper';


export default {

name:'MeScroll',

components:{

Swiper,

SwiperSlide

},

props:{

scrollbar:{

type:Boolean,

default:true

},

data1:{

type:[Array,Object]     // 数组或者对象

}

},

data(){

return{

swiperOption:{

direction: 'vertical',

slidesPerView: 'auto',

freeMode: true,

setWrapperSize: true,

scrollbar: {

el: this.scrollbar ? '.swiper-scrollbar' : null,

hide: true

}

}

}

},

watch:{

data1(){

this.update()

}

},

methods:{

update(){

this.$refs.swiper && this.$refs.swiper.swiper.update()  // 更新滚动条,用swiper提供的api

}

}

}

</script>


<style lang="scss" scoped>

.swiper-container{

overflow: hidden;

width: 100%;

height: 100%;

}

.swiper-slide{

height: auto;

}

</style>

----------------------------------------------------

http://img1.sycdn.imooc.com//climg/5ea82e5b09999d0e13020538.jpg------------------------

老师这是哪里不对

正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,应该是版本的问题,老师授课时使用的版本是3.1.1。 同学修改后项目可以正常使用就可以了。

不过同学目前在学习阶段,推荐与老师讲解的版本保持一致会更好哦。示例:使用如下命令安装

npm install vue-awesome-swiper@3.1.1 -D

祝学习愉快~

好帮手慕慕子 2020-04-29 10:47:01

同学你好,只有部分代码无法进行测试,建议:将home/index.vue代码粘贴过来,另,将package.json中使用的swiper和vue-awesome-swiper插件的版本也粘贴过来,老师帮助同学更准确的测试下代码。

祝学习愉快~

  • 改成这样就可以了this.$refs.swiper && this.$refs.swiper.$swiper.update(),在swiper前头加了个$,这是因为swiper版本的事吗?我安装的版本是"swiper": "^5.3.7", "vue-awesome-swiper": "^4.1.1"
    2020-04-29 14:29:43
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师