查看: 3311|回复: 9
打印 上一主题 下一主题

swiper手机端bug,大神出手相助

[复制链接]
  • TA的每日心情
    慵懒
    2018-1-12 14:53
  • 签到天数: 2 天

    [LV.1]初来乍到

    2

    主题

    9

    帖子

    48

    积分

    新手上路

    Rank: 1

    积分
    48
    跳转到指定楼层
    楼主
    发表于 2018-1-3 10:18:51 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
    <template>
      <section class="scroll-wrapper" :style="{ height: clientHeight + 'px' }">
        <section class="main-wrapper">
            <swiper ptions="swiperOption">
              <div class="swiper-slide" v-for="picture in pictures">
                <div class="swiper-zoom-container">
                  <img class="swiper-img" v-bind:src="picture.url"/>
                </div>
              </div>
              <div v-show="pictures.length > 1" class="swiper-pagination" slot="pagination"></div>
            </swiper>
        </section>
      </section>
    </template>

    <script>
    import {getScrollTop, getWindowHeight, setDocumentTitle} from '../../../../../static/h5/utils/interaction'
    import { swiper, swiperSlide } from 'vue-awesome-swiper'
    import PackageSpecs from '../../components/PackageSpecs'
    import Btn from '../../components/Btn'

    export default {
      data () {
        return {
          newsId: '',
          pictures: [],
          bullets: true,
          clientHeight: 0,
          swiperOption: {
            zoom: true,
            notNextTick: true,
            mode: 'horizontal',
            speed: 300,
            loop: false,
            observer: true,
            observeParents: true,
            pagination: '.swiper-pagination',
            paginationClickable: true,
            spaceBetween: 30
          }
        }
      },
      ready () {
        let params = {
          newsId: this.$route.query.newsId
        }
        this.$resource('main/news/get-news-detail').get(params).then((resp) => {
          let news = resp.data.item
          this.pictures = news.pictures
        })
        setDocumentTitle('品牌要闻')
      },
      components: {
        swiper,
        swiperSlide,
        PackageSpecs,
        Btn
      }
    }
    </script>

    <style lang="less" scoped>
    @import "./shownewspictures.less";
    </style>


    是在vue里面引入的swiper,之前用多个div包裹img,用静态的图片url 一切都可以正常使用,换上v-for之后 动态的从后台拿数据就出现手滑放大失效,双击放大,图片无法拖动的情况

    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏1 分享分享 分享淘帖
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2018-1-12 14:53
  • 签到天数: 2 天

    [LV.1]初来乍到

    2

    主题

    9

    帖子

    48

    积分

    新手上路

    Rank: 1

    积分
    48
    推荐
     楼主| 发表于 2018-1-3 10:25:50 | 只看该作者
    图片双击放大之后,再拖动就会出现重叠的情况
    回复 支持 1 反对 0

    使用道具 举报

  • TA的每日心情
    无聊
    2018-1-18 08:54
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    0

    主题

    9

    帖子

    57

    积分

    注册会员

    Rank: 2

    积分
    57
    10#
    发表于 2018-1-18 08:54:11 | 只看该作者
    获取数据回调里面直接this.swiper(自己的名字).init()就可以了;或者用了async和await就写在那个函数下面就行,不过如果你的图片很多或者做阅读器等的话,建议不要用这个插件,因为我又发现别的新bug了,还是原始swiper引入使用靠谱点,想比较而言bug少一些
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2018-1-12 14:53
  • 签到天数: 2 天

    [LV.1]初来乍到

    2

    主题

    9

    帖子

    48

    积分

    新手上路

    Rank: 1

    积分
    48
    9#
     楼主| 发表于 2018-1-11 20:21:08 | 只看该作者
    xiaofu 发表于 2018-1-7 15:08
    自己已经解决了,需要在swiperOption里面init:false,然后异步取得数据后重新init才行,因为默认int还没数 ...

    对 我再看了一下,但是我不知道在那里init,能告知一下吗
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2018-1-12 14:53
  • 签到天数: 2 天

    [LV.1]初来乍到

    2

    主题

    9

    帖子

    48

    积分

    新手上路

    Rank: 1

    积分
    48
    8#
     楼主| 发表于 2018-1-10 17:25:49 | 只看该作者
    jianghanhanhan 发表于 2018-1-10 17:07
    export default {
      data () {
        return {

    我的一直都是在swiper-zoom-container 的translate里面变化的
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2018-1-12 14:53
  • 签到天数: 2 天

    [LV.1]初来乍到

    2

    主题

    9

    帖子

    48

    积分

    新手上路

    Rank: 1

    积分
    48
    7#
     楼主| 发表于 2018-1-10 17:07:11 | 只看该作者
    xiaofu 发表于 2018-1-7 15:08
    自己已经解决了,需要在swiperOption里面init:false,然后异步取得数据后重新init才行,因为默认int还没数 ...

    export default {
      data () {
        return {
          newsId: '',
          pictures: [],
          bullets: true,
          clientHeight: 0,
          swiperOption: {
            init: false,
            zoom: true,
            notNextTick: true,
            mode: 'horizontal',
            speed: 300,
            loop: false,
            observer: true,
            observeParents: true,
            pagination: '.swiper-pagination',
            paginationClickable: true,
            spaceBetween: 30
          }
        }
      },
      ready () {
        let params = {
          newsId: this.$route.query.newsId
        }
        this.$resource('main/news/get-news-detail').get(params).then((resp) => {
          let news = resp.data.item
          this.pictures = news.pictures
          this.init = true
        })
        setDocumentTitle('品牌要闻')
      },
      components: {
        Hammer,
        swiper,
        swiperSlide,
        PackageSpecs,
        Btn
      }
    }
    </script>

    <style lang="less" scoped>
    @import "./shownewspictures.less";
    </style>



    是这样操作吗,还是没有效果呢
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2018-1-18 08:54
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    0

    主题

    9

    帖子

    57

    积分

    注册会员

    Rank: 2

    积分
    57
    6#
    发表于 2018-1-7 15:08:37 | 只看该作者
    自己已经解决了,需要在swiperOption里面init:false,然后异步取得数据后重新init才行,因为默认int还没数据放大后swiper-zoom-container不会正常translate,我在github问过也关闭了这个问题,希望对你有帮助
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2018-1-18 08:54
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    0

    主题

    9

    帖子

    57

    积分

    注册会员

    Rank: 2

    积分
    57
    5#
    发表于 2018-1-5 17:55:24 | 只看该作者
    我发现是swiper-zoom-container的translate没有变化造成的,只是放大的一瞬间变化了,再拖动的时候就只是swiper-wrapper的tranlate在变化,正常应该是swiper-zoom-container的translate变化就正常了,问题找到了,具体怎么改我还在看
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2018-1-18 08:54
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    0

    主题

    9

    帖子

    57

    积分

    注册会员

    Rank: 2

    积分
    57
    地板
    发表于 2018-1-5 11:35:11 | 只看该作者
    这个是swiper的bug还是vue-awesome-swiper的bug呢,楼主github上问了么
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2018-1-18 08:54
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    0

    主题

    9

    帖子

    57

    积分

    注册会员

    Rank: 2

    积分
    57
    板凳
    发表于 2018-1-5 11:32:44 | 只看该作者
    遇见相同情况,有木有长的帅的,美的来解决下
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Swiper中文网 ( 粤ICP备15001020号

    GMT+8, 2024-9-29 13:15 , Processed in 0.068699 second(s), 28 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表