收藏
回答

如何通过点击按钮事件触发swiper控件滚动到某一页?

如题 比如 点击第三个按钮 swiper组件就滚动到第三页中

回答关注问题邀请回答
收藏

5 个回答

  • 茜茜又困了🐽
    茜茜又困了🐽
    2022-07-12

    wxml:

    <swiper current = "{{ currentIndex }}">...</swiper>

    <button bindtap="btnTap">点击</button>

    js:

    btnTap() {

    this.setData({

    currentIndex: 3

    })

    }

    2022-07-12
    有用 1
    回复 10
    • 👦🏾
      👦🏾
      发表于移动端
      2022-07-12
      我swiper是写成了一个组件
      2022-07-12
      1
      回复
    • 茜茜又困了🐽
      茜茜又困了🐽
      2022-07-12回复👦🏾
      代码呢?
      2022-07-12
      1
      回复
    • 👦🏾
      👦🏾
      2022-07-12
      我写了一个banner组件  然后页面是引用这个banner组件了
      2022-07-12
      回复
    • 茜茜又困了🐽
      茜茜又困了🐽
      2022-07-12回复👦🏾
      没猜错的话,你现在的问题是修改current的值,然后子组件内的current不更新对吧?
      2022-07-12
      1
      回复
    • 👦🏾
      👦🏾
      2022-07-12回复茜茜又困了🐽
      是的 然后我看了下 标签的值 是0
      2022-07-12
      回复
    查看更多(5)
  • 澄c澄悦
    澄c澄悦
    2022-07-12

    https://developers.weixin.qq.com/s/ABfrZHmD7eAj,试了下没问题啊,通过改变current切换swiper

    2022-07-12
    有用
    回复
  • 睡前原谅一切
    睡前原谅一切
    2022-07-12

    修改current 就可以滚动到对应的页面

    2022-07-12
    有用
    回复
  • Q1an
    Q1an
    2022-07-12

    动态设置swiper current的值不就行了吗

    2022-07-12
    有用
    回复
  • ⅴ
    2022-07-12

    https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html

    通过点击按钮改变current值

    2022-07-12
    有用
    回复
登录 后发表内容