這篇文章主要介紹了微信小程序聯(lián)網(wǎng)請求的輪播圖的相關(guān)資料,需要的朋友可以參考下
微信小程序的輪播圖和Android的輪播圖一點(diǎn)不一樣 ,這里我們看一下我們需要用到的控件介紹
這里我們用到了swiper這個組件,上邊的圖片已經(jīng)把這個組件的屬性 都列出來了 我們用的時候直接用就可以了 接下來,再看一下網(wǎng)絡(luò)請求的API,這里我們用到的是GET 請求,我們開一下微信小程序官方給我們的API
接下來就是開啟我們小程序輪播圖之旅了,附上一張效果圖
首先,我們看一下我們的index.wxml文件
<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>
登錄后復(fù)制
index.js文件
var app = getApp() Page({ /** * 頁面的初始數(shù)據(jù) */ data: { //是否顯示指示點(diǎn) true 顯示 false 不顯示 indicatorDots: true, //控制方向 vertical: false, //是否自動切換 autoplay: true, //自動切換時間間隔 interval: 3000, //滑動動畫時長 duration: 1000, }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { var that = this //調(diào)用應(yīng)用實(shí)例的方法獲取全局?jǐn)?shù)據(jù) app.getUserInfo(function (userInfo) { //更新數(shù)據(jù) that.setData({ userInfo: userInfo }) }) //網(wǎng)絡(luò)請求 GET方法 wx.request({ url: 'http://huanqiuxiaozhen.com/wemall/slider/list', method: 'GET', data: {}, header: { 'Accept': 'application/json' }, //成功后的回調(diào) success: function (res) { console.log('11111' + res), that.setData({ images: res.data }) } }) } })
登錄后復(fù)制
index.wxss 這里就是簡單的控制了一下顯示的樣式
.swiper_box { width: 100%; } swiper-item image { width: 100%; display: inline-block; overflow: hidden; }
登錄后復(fù)制
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請關(guān)注PHP中文網(wǎng)!
相關(guān)推薦:
以上就是微信小程序聯(lián)網(wǎng)請求的輪播圖的詳細(xì)內(nèi)容,更多請關(guān)注有卡有網(wǎng)。