微信小程序轮播图swiper使用


一、swiper?

小程序中创建轮播图。

二、使用步骤

1.引入代码

微信开放文档中组件--》视图容器--》swiper将下面代码拷贝

 

2.修改代码

将代码粘贴至需要轮播图的页面,并根据实际情况修改代码

<view class="container">
  <swiper indicator-dots autoplay interval="{{2000}}">
        <block wx:for="{{tabList}}" wx:key="*this">
          <swiper-item class="swiper-item">
          <image src="{{item.img}}"></image>
          </swiper-item>
        </block>
      </swiper>
</view>

这里的tabList和img是根据接口传来的数据,需要在js中定义,这里定义的tabList通过onLoad方法,将接口传来的数据赋值给tabList 

onLoad(){
    let _this=this;
    wx.request({
      url: 'http://localhost:8881/home/swiper', 
      data: {
      },
      method:"Get",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        _this.setData({
          tabList:res.data
        })
        console.log(res.data)
      }
    })

  },

上面swiper标签中的属性,根据实际情况修改,属性如下

 


3、展示效果

 

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值