小程序?qū)崿F(xiàn)簡單分頁組件
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)簡單分頁組件的具體代碼,供大家參考,具體內(nèi)容如下
wxml:
?<!-- 分頁組件 --> ? ? <view class="page_div"> ? ? ? <view class="page_sum">共{{pagetotal}}頁</view> ? ? ? <view class="page_prev" bindtap="prevFn">上一頁</view> ? ? ? <view class="page_number_div"> ? ? ? ? <input value="{{pageNumber}}" bindinput="inputValue" data-name="pageNumber"></input> ? ? ? ? <view class="pageGo" bindtap="pageGo">Go</view> ? ? ? </view> ? ? ? <view class="page_next" bindtap="nextFn">下一頁</view> </view>
wxss:
/************分頁樣式****************/ .page_div{ ? display: flex; ? width: 100%; ? justify-content: flex-end; ? box-sizing: border-box; ? padding:20rpx; ? background-color: #fff; } .page_div .page_sum, .page_div .page_prev, .page_div .page_number_div, .page_div .page_next{ ? height: 50rpx; ? line-height: 50rpx; ? font-size:24rpx; ? color: #333; } .page_div .page_prev, .page_div .page_next{ ? background-color: #eee; ? padding:0 10rpx; ? margin:0 10rpx; } .page_div .page_number_div .pageGo{ ? display: inline-block; ? vertical-align: middle; ? width: 50rpx; ? box-sizing: border-box; ? background-color: #eee; ? text-align: center; ? margin:0 10rpx; } .page_div .page_number_div input{ ? width: 100rpx; ? display: inline-block; ? vertical-align: middle; ? text-align: center; ? border:1px solid #eee; } /************分頁樣式結(jié)束************/
js:
Page({ ? data: { ? ? //分頁數(shù)據(jù) ? ? pageNumber:1, ? ? pagetotal:5, ? ? page:1 ? }, ? onLoad: function (options) { ? ? ? }, ? //input輸入雙向綁定數(shù)據(jù) ? inputValue:function(e){ ? ? let name = e.currentTarget.dataset.name; ? ? let mapName ={}; ? ? mapName[name]=e.detail && e.detail.value; ? ? // console.log(mapName); ? ? this.setData(mapName); ? }, ? //上一頁 ? prevFn:function(){ ? ? if(this.data.pageNumber <=1){ ? ? ? wx.showToast({ ? ? ? ? icon:'none', ? ? ? ? title: '已經(jīng)是最前一頁', ? ? ? }) ? ? ? return; ? ? } ? ?? ? ? wx.showLoading({ ? ? ? title: '加載中...', ? ? }) ? ? this.setData({ ? ? ? pageNumber:Number(this.data.pageNumber)-1 ? ? }) ? ? console.log(this.data.pageNumber); ? ? setTimeout(function(){ ? ? ? wx.hideLoading() ? ? },1000) ? }, ? //下一頁 ? nextFn:function(){ ? ? if(this.data.pageNumber === this.data.pagetotal){ ? ? ? wx.showToast({ ? ? ? ? icon:'none', ? ? ? ? title: '已經(jīng)是最后一頁', ? ? ? }) ? ? ? return; ? ? } ? ? wx.showLoading({ ? ? ? title: '加載中...', ? ? }) ? ? this.setData({ ? ? ? pageNumber:Number(this.data.pageNumber)+1 ? ? }) ? ? console.log(this.data.pageNumber); ? ? setTimeout(function(){ ? ? ? wx.hideLoading() ? ? },1000) ? }, ? //去到某一頁 ? pageGo:function(){ ? ? console.log(Number(this.data.pageNumber)); ? ? if(Number(this.data.pageNumber) > this.data.pagetotal){ ? ? ? this.setData({ ? ? ? ? pageNumber:this.data.pagetotal ? ? ? }) ? ? }else if(Number(this.data.pageNumber) <= 0){ ? ? ? this.setData({ ? ? ? ? pageNumber:1 ? ? ? }) ? ? } ? ? console.log(Number(this.data.pageNumber)); ? ? wx.showLoading({ ? ? ? title: '加載中...', ? ? }) ? ? setTimeout(function(){ ? ? ? wx.hideLoading() ? ? },1000) ? } })
效果圖:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Javascript(AJAX)解析XML的代碼(兼容FIREFOX/IE)
Javascript AJAX 解析XML的代碼(兼容FIREFOX/IE)2010-07-07動態(tài)創(chuàng)建樣式表在各瀏覽器中的差異測試代碼
對于標(biāo)準(zhǔn)瀏覽器,直接使用css.innerHTML也可以修改HTMLStyleElement的css規(guī)則2011-09-09利用策略模式與裝飾模式擴(kuò)展JavaScript表單驗(yàn)證功能
這篇文章主要介紹了利用策略模式與裝飾模式擴(kuò)展JavaScript表單驗(yàn)證功能,需要的朋友可以參考下2017-02-02正則表達(dá)式在js前端的15個(gè)使用場景梳理總結(jié)
本篇帶來15個(gè)正則使用場景,按需索取,收藏恒等于學(xué)會??!有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07javascript 構(gòu)造函數(shù)強(qiáng)制調(diào)用經(jīng)驗(yàn)總結(jié)
本文將介紹javascript構(gòu)造函數(shù)調(diào)用方面的案例應(yīng)用,需要了解的朋友可以參考下2012-12-12教你JS中的運(yùn)算符乘方、開方及變量格式轉(zhuǎn)換
本文運(yùn)用實(shí)例教大家JS中的運(yùn)算符乘方、開方及變量格式轉(zhuǎn)換,代碼簡單明了,有需要的可以參考學(xué)習(xí)。2016-08-08