wxCardSwiper
小程序卡片切換效果組件. 支持異步添加卡片數(shù)據(jù), 手勢(shì)滑動(dòng)觸發(fā).
源碼地址: https://github.com/doterlin/wxCardSwiper
使用方法
將本項(xiàng)目文件中的components/cardSwiper
文件夾復(fù)制到你項(xiàng)目的目錄下聪轿,然后在頁(yè)面的json配置及頁(yè)面引入况毅。自定義組件的引入和使用請(qǐng)參考官方文檔良价。
本項(xiàng)目包含組件和頁(yè)面demo抖部,可直接運(yùn)行(上滑翻到下一張,下滑回到上一張)轩拨。
參數(shù)
-
data
Array
傳入的初始數(shù)據(jù)數(shù)組 -
loadmore
事件
當(dāng)需要加載更多數(shù)據(jù)時(shí)出發(fā)鸡号。
示例
demo
yourPage.json
頁(yè)面配置(下面的路徑換成你copy到項(xiàng)目的path)
{
"usingComponents": {
"CardSwiper": "/components/cardSwiper/cardSwiper"
}
}
yourPage.wxml
頁(yè)面結(jié)構(gòu)
<CardSwiper data="{{swiperData}}" bindloadmore="loadMore"> </CardSwiper>
yourPage.js
頁(yè)面js
Page({
data: {
currentPage: 0,
totalPage: 2,
swiperData: [{
name: "page: 0, index: 1"
},{
name: "page: 0, index: 2"
},{
name: "page: 0, index: 3"
}]
},
loadMore({detail}){
if(this.data.currentPage >= this.data.totalPage) return; //大于總頁(yè)數(shù)時(shí)退出
wx.request({
url: 'yourApiurl', //僅為示例,并非真實(shí)的接口地址
data: {
page: this.data.currentPage,
},
success (res) {
detail.addToList(res.data); //調(diào)用detail.addToList將新數(shù)據(jù)累加到組件內(nèi)部數(shù)據(jù)
}
})
}
})
更詳細(xì)示例請(qǐng)參考本項(xiàng)目中pages/index
頁(yè)面
修改樣式
如果樣式和結(jié)構(gòu)不能滿足展示需求恢筝,你需要到cardSwiper組件里自行修改wxml
和wxss
代碼哀卫。