微信小程序的輪播圖和Android的輪播圖

微信小程序的輪播圖和Android的輪播圖一點不同 ,這裏咱們看一下咱們須要用到的控件介紹

這裏寫圖片描述

 

這裏咱們用到了swiper這個組件,上邊的圖片已經把這個組件的屬性 都列出來了 咱們用的時候直接用就能夠了 
接下來,再看一下網絡請求的API,這裏咱們用到的是GET 請求,咱們開一下微信小程序官方給咱們的API

這裏寫圖片描述
這裏寫圖片描述

接下來就是開啓咱們小程序輪播圖之旅了,附上一張效果圖

首先,咱們看一下咱們的index.wxml文件javascript

<view>
 <swiper class="swiper_box" indicator-dots="{{indicatorDots}}" vertical="{{vertical}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" bindchange="swiperchange">
    <block wx:for="{{images}}">
      <swiper-item>
        <image src="{{item.picurl}}" class="slide-image" />
      </swiper-item>
    </block>
  </swiper>
</view>
  •  

index.js文件java

var app = getApp()
Page({

  /**
   * 頁面的初始數據
   */
  data: {
    //是否顯示指示點 true 顯示 false 不顯示
    indicatorDots: true,
    //控制方向
    vertical: false,
    //是否自動切換
    autoplay: true,
    //自動切換時間間隔
    interval: 3000,
    //滑動動畫時長
    duration: 1000,
  },

  /**
   * 生命週期函數--監聽頁面加載
   */
  onLoad: function (options) {
    var that = this
    //調用應用實例的方法獲取全局數據
    app.getUserInfo(function (userInfo) {
      //更新數據
      that.setData({
        userInfo: userInfo
      })
    })
    //網絡請求 GET方法
    wx.request({
      url: 'http://huanqiuxiaozhen.com/wemall/slider/list',
      method: 'GET',
      data: {},
      header: {
        'Accept': 'application/json'
      },
      //成功後的回調
      success: function (res) {
        console.log('11111' + res),
          that.setData({
            images: res.data
          })
      }
    })
  }
})
  •  

index.wxss 這裏就是簡單的控制了一下顯示的樣式json

.swiper_box {
    width: 100%;
}

swiper-item image {
    width: 100%;
    display: inline-block;
    overflow: hidden;
}
相關文章
相關標籤/搜索