Vue-awesome-swiper: 垂直滚动的时候,页面计算swiper-slide高度不对,而是一个屏幕放了五个模块

Created on 18 Dec 2017  ·  7Comments  ·  Source: surmon-china/vue-awesome-swiper

Vue.js version : 2.5.2 and component version : 3.0.4
粘贴vue-awesome-swiper/examples/27-mousewheel-control.vue,无法进行页面的初始化
不是事例中的一面一屏,而是一个屏幕放了五个模块

查看源码后发现,没有调用Slide.vue的update()方法

目前我自己的解决方案是,在vue的mounted回调里,设置一个定时器,调用update()

    setTimeout(() => {
        this.swiper.update()
     }, 20)

Most helpful comment

swiperOption: {
        direction: 'vertical',
        slidesPerView: 1,
        mousewheel: true,
        height: window.innerHeight  // 高度占满整个设备高度
}

All 7 comments

你可以尝试用 css 给 swiper-slide 的高度设置为屏幕的 100%。

容器的 100%

已经尝试过了,这方法不行,底层的Swiper组件会自动执行一次计算,然后每次滑动就按照这个高度来

swiperOption: {
        direction: 'vertical',
        slidesPerView: 1,
        mousewheel: true,
        height: window.innerHeight  // 高度占满整个设备高度
}

表示同样遇到这个问题.。
@kaindy7633 使用kaindy的方法就解决了,不知道还有没有更好的方法。

if (process.browser) { height = window.innerHeight;//客户端环境把高度设置为整个设备高度 }

global.height = height;

swiperOption: {
         direction: 'vertical',
         mousewheel: true,
         height : global.height//指定swiper的每屏高度
 }

swiper设置css style="overflow: hidden; height: 800px;"

不做全屏滚动的时候呢,必须要容器固定高度才能用vertical么?不能像水平切换的时候那样autoHeight?

Was this page helpful?
0 / 5 - 0 ratings