<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        微信小程序自定義組件實現tabs選項卡功能

        來源:懂視網 責編:小OO 時間:2020-11-27 22:11:38
        文檔

        微信小程序自定義組件實現tabs選項卡功能

        本文為大家分享了微信小程序實現tabs選項卡功能的具體代碼,供大家參考,具體內容如下:一個自定義組件由 json wxml wxss js 4個文件組成。要編寫一個自定義組件,首先需要在 json 文件中進行自定義組件聲明(將 component 字段設為 true 可這一組文件設為自定義組件)。components/navigator/index.json。{ "component": true}。components/navigator/index.wxml。
        推薦度:
        導讀本文為大家分享了微信小程序實現tabs選項卡功能的具體代碼,供大家參考,具體內容如下:一個自定義組件由 json wxml wxss js 4個文件組成。要編寫一個自定義組件,首先需要在 json 文件中進行自定義組件聲明(將 component 字段設為 true 可這一組文件設為自定義組件)。components/navigator/index.json。{ "component": true}。components/navigator/index.wxml。

        本文為大家分享了微信小程序實現tabs選項卡功能的具體代碼,供大家參考,具體內容如下

        一個自定義組件由 json wxml wxss js 4個文件組成。要編寫一個自定義組件,首先需要在 json 文件中進行自定義組件聲明(將 component 字段設為 true 可這一組文件設為自定義組件)

        components/navigator/index.json

        {
         "component": true
        }

        components/navigator/index.wxml

        <!-- 自定義tab標簽組件-->
        <!-- 標題列表-->
        <scroll-view scroll-x="true" class="scroll-view-x" wx:if="{{!ttype || ttype==2}}">
         <view class="scroll-view-item" wx:for="{{tList}}" wx:key="*this">
         <view class="{{currentTab==(index) ? 'on' : ''}}" bindtap="_swichNav" data-current="{{index}}">{{ !tname ? item.name : item[tname].name }}</view>
         </view>
        </scroll-view>
        <!--內容列表-->
        <slot>
        </slot>
        

        components/navigator/index.js

        //組件的對外屬性,是屬性名到屬性設置的映射表,屬性設置中可包含三個字段, type 表示屬性類型、 value 表示屬性初始值、 observer 表示屬性值被更改時的響應函數
        Component({
         properties:{
         //標題列表
         tList:{
         type: Array,
         value:[]
         }, 
         //當前tab index
         currentTab:{
         type:Number,
         value:0,
         observer: function (newVal, oldVal) { 
         this.setData({
         currentTab : newVal
         })
         } 
         }
         },
         //組件的方法,包括事件響應函數和任意的自定義方法,關于事件響應函數的使用
         methods:{
         // 內部方法建議以下劃線開頭
         _swichNav:function(e){
         //自定義組件觸發事件時,需要使用 triggerEvent 方法,指定事件名、detail對象和事件選項
         this.triggerEvent('changeCurrent', {
         currentNum: e.currentTarget.dataset.current
         })
         }
         }
        })

        components/navigator/index.wxss

        .scroll-view-x{
         background-color: #fff;
         white-space: nowrap;
         position:fixed;
         z-index:10;
         top:0
        }
        .scroll-view-x .scroll-view-item{
         display:inline-block;
         margin:0 35rpx;
         line-height: 33px;
         cursor: pointer;
        }
        .on{
         border-bottom: 2px solid red;
         color: red
        }

        使用自定義組件

        使用已注冊的自定義組件前,首先要在頁面的 json 文件中進行引用聲明。此時需要提供每個自定義組件的標簽名和對應的自定義組件文件路徑:

        pages/order-list/index.json

        {
         "navigationBarTitleText":"訂單列表",
         "usingComponents": {
         "slideTab": "../../components/navigator/index"
         }
        }

        這樣,在頁面的 wxml 中就可以像使用基礎組件一樣使用自定義組件。節點名即自定義組件的標簽名,節點屬性即傳遞給組件的屬性值。

        pages/order-list/index.wxml

        <view >
         <slideTab tList="{{statusType}}" bind:changeCurrent="swichNav" currentTab="{{currentType}}" >
         <swiper current="{{currentType}}" duration="300" bindchange="bindChange" style="height: {{windowHeight-35}}px;margin-top:35px;">
         <block>
         <swiper-item wx:for="{{list}}">
         <view class="no-order" hidden="{{item.length ? true : false}}">
         <image src="../../assets/imgs/no-order.png" class="no-order-img"></image>
         <view class="text">暫無訂單</view>
         </view>
         <scroll-view scroll-y="true" class="order-list" scroll-with-animation="true" lower-threshold="1" bindscrolltolower="scrolltolower" style="height: {{windowHeight-35}}px;" hidden="{{item ? flase : true}}">
         <view class="a-order" wx:for="{{item}}" wx:key="childIndex" wx:for-item="childItem" >
         <view class="order-date">
         <view class="date-box">下單時間:{{childItem.dateAdd}}</view>
         <view class="status {{(childItem.status==-1 || childItem.status==4) ? '':'red'}}">{{item.statusStr}}</view>
         </view>
         <view class="goods-info" bindtap="orderDetail" data-id="{{childItem.id}}">
         <view class="goods-des">
         <view>訂單號 : {{childItem.orderNumber}} </view>
         <view wx:if="{{childItem.remark && childItem.remark != ''}}">備注: {{item.remark}}</view>
         </view>
         </view>
         <view >
         <scroll-view class="goods-img-container" scroll-x="true">
         <view class="img-box" wx:for="{{goodsMap[currentType][childItem.id]}}" wx:for-item="child_item">
         <image src="{{child_item.pic}}" class="goods-img"></image>
         </view>
         </scroll-view>
         </view>
         <view class="price-box">
         <view class="total-price">合計:¥ {{childItem.amountReal}}</view>
         <view class="btn cancel-btn" hidden="{{childItem.status==0? false : true}}" bindtap="cancelOrderTap" data-id="{{childItem.id}}">取消訂單</view>
         <view class="btn topay-btn" hidden="{{childItem.status==0? fslse : true}}" bindtap="toPayTap" data-id="{{childItem.id}}" data-money="{{childItem.amountReal}}">馬上付款</view> 
         </view> 
         </view>
         </scroll-view>
         </swiper-item>
         </block>
         </swiper>
         </slideTab>
        </view>

        pages/order-list/index.js

        var wxpay = require('../../utils/pay.js')
        var app = getApp();
        Page({
         data:{
         statusType:[
         {name:"待付款",page:0},
         {name:"待發貨",page:0},
         {name:"待收貨",page:0},
         {name:"待評價",page:0},
         {name:"已完成",page:0}],
         currentType:0,
         list:[[],[],[],[],[]],
         goodsMap:[{},{},{},{},{}],
         logisticsMap:[{},{},{},{},{}],
         windowHeight:''
         },
         onLoad(options){
         this.getList();
         var systemInfo = wx.getSystemInfoSync()
         this.setData({
         windowHeight: systemInfo.windowHeight,
         currentType:options.id ? options.id:0
         })
         },
         // 點擊tab切換 
         swichNav: function (res) {
         if (this.data.currentType == res.detail.currentNum) return;
         this.setData({
         currentType: res.detail.currentNum
         })
         } , 
         bindChange:function(e){
         this.setData({
         currentType: e.detail.current
         })
         if (!this.data.list[e.detail.current].length)
         this.getList();
         } ,
         getList(){
         wx.showLoading();
         var that = this;
         var postData = {
         token: app.globalData.token,
         status: that.data.currentType
         };
         var _page = that.data.statusType[that.data.currentType].page+1 ;;
         wx.request({
         url: app.globalData.baseUrl + '/order/list',
         data: postData,
         success: (res) => {
         wx.hideLoading();
         var param = {}, str1 = "list[" + that.data.currentType + "]", str2 = 'statusType[' + that.data.currentType + '].page', str3 = "logisticsMap[" + that.data.currentType + "]", str4 = "goodsMap[" + that.data.currentType + "]" ;
         if (res.data.code == 0) {
         param[str1] = res.data.data.orderList ;
         param[str2] = _page ;
         param[str3] = res.data.data.logisticsMap ;
         param[str4] = res.data.data.goodsMap ;
         that.setData(param);
         } else {
         param[str1] = [];
         param[str3]= {};
         param[str4] = {};
         this.setData(param);
         }
         }
         })
         },
         orderDetail: function (e) {
         var orderId = e.currentTarget.dataset.id;
         wx.navigateTo({
         url: "/pages/order-details/index?id=" + orderId
         })
         },
         cancelOrderTap: function (e) {
         var that = this;
         var orderId = e.currentTarget.dataset.id;
         wx.showModal({
         title: '確定要取消該訂單嗎?',
         content: '',
         success: function (res) {
         if (res.confirm) {
         wx.showLoading();
         wx.request({
         url: app.globalData.baseUrl + '/order/close',
         data: {
         token: app.globalData.token,
         orderId: orderId
         },
         success: (res) => {
         wx.hideLoading();
         if (res.data.code == 0) {
         var param = {}, str = 'statusType[' + that.data.currentType + '].page';
         param[str]=0;
         that.getList();
         }
         }
         })
         }
         }
         })
         }
        })

        pages/order-list/index.wxss

        .container{
         width: 100%;
         background-color: #F2f2f2;
        }
        .status-box{
         width:100%;
         height: 88rpx;
         line-height: 88rpx;
         display: flex;
         justify-content: space-between;
         align-items: center;
         background-color: #fff;
        }
        .status-box .status-label{
         width: 150rpx;
         height: 100%;
         text-align: center;
         font-size:28rpx;
         color:#353535;
         box-sizing: border-box;
         position: relative;
        }
        .status-box .status-label.active{
         color:#e64340;
         border-bottom: 6rpx solid #e64340;
        }
        .status-box .status-label .red-dot{
         width: 16rpx;
         height: 16rpx;
         position: absolute;
         left: 116rpx;
         top:23rpx;
         background-color: #f43530;
         border-radius: 50%;
        }
        .no-order{
         width: 100%;
         position: absolute;
         bottom: 0;
         top:0;
         left: 0;
         right: 0;
         text-align: center;
         padding-top: 203rpx;
         background-color: #F2f2f2;
        }
        .no-order-img{
         width: 81rpx;
         height: 96rpx;
         margin-bottom: 31rpx;
        }
        .no-order .text{
         font-size:28rpx;
         color:#999999;
         text-align: center
        }
        .order-list{
         width: 100%;
        }
        .order-list .a-order{
         width: 100%;
         background-color: #fff;
         margin-top: 20rpx;
        }
        .order-list .a-order .order-date{
         padding: 0 30rpx;
         height: 88rpx;
         display: flex;
         justify-content: space-between;
         font-size:26rpx;
         color:#000000;
         align-items: center;
        }
        .order-list .a-order .order-date .red{
         font-size:26rpx;
         color:#e64340;
        }
        .a-order .goods-info,
        .goods-img-container{
         width: 720rpx;
         margin-left: 30rpx;
         border-top: 1rpx solid #eee;
         border-bottom: 1rpx solid #eee;
         padding: 30rpx 0;
         display: flex;
         align-items: center;
        }
        .goods-info .img-box{
         width: 120rpx;
         height: 120rpx;
         overflow: hidden;
         margin-right: 30rpx;
         background-color: #f7f7f7;
        }
        .goods-info .img-box .goods-img,
        .goods-img-container .img-box .goods-img{
         width: 120rpx;
         height: 120rpx;
        }
        .goods-info .goods-des{
         width: 540rpx;
         height: 78rpx;
         line-height: 39rpx;
         font-size:26rpx;
         color:#000000;
         overflow: hidden;
        }
        .goods-img-container{
         height: 180rpx;
         box-sizing: border-box;
         white-space: nowrap;
        }
        .goods-img-container .img-box{
         width: 120rpx;
         height: 120rpx;
         overflow: hidden;
         margin-right: 20rpx;
         background-color: #f7f7f7;
         display: inline-block;
        }
        .order-list .a-order .price-box{
         position: relative;
         width: 720rpx;
         height: 100rpx;
         margin-left: 30rpx;
         box-sizing: border-box;
         padding: 20rpx 30rpx 20rpx 0;
         display: flex;
         align-items: center;
         justify-content: space-between;
         font-size:26rpx;
        }
        .order-list .a-order .price-box .total-price{
         font-size:26rpx;
         color:#e64340;
        }
        .a-order .price-box .btn{
         width: 166rpx;
         height: 60rpx;
         box-sizing: border-box;
         text-align: center;
         line-height: 60rpx;
         border-radius: 6rpx;
         margin-left: 20rpx;
        }
        .a-order .price-box .cancel-btn{
         border: 1rpx solid #ccc;
         position: absolute;
         right: 216rpx;
         top:20rpx;
        }
        .a-order .price-box .topay-btn{
         border:1px solid #e64340;
         color: #e64340;
        }
        
        

        效果圖

        這里寫圖片描述

        項目地址:微信小程序實現tabs選項卡功能

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        微信小程序自定義組件實現tabs選項卡功能

        本文為大家分享了微信小程序實現tabs選項卡功能的具體代碼,供大家參考,具體內容如下:一個自定義組件由 json wxml wxss js 4個文件組成。要編寫一個自定義組件,首先需要在 json 文件中進行自定義組件聲明(將 component 字段設為 true 可這一組文件設為自定義組件)。components/navigator/index.json。{ "component": true}。components/navigator/index.wxml。
        推薦度:
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 成人毛片免费播放| 中国在线观看免费的www| 四虎精品视频在线永久免费观看| 国产精品亚洲精品日韩已方| 一区二区三区在线免费观看视频| 国产又黄又爽又刺激的免费网址 | 青青草原亚洲视频| 成人片黄网站色大片免费观看cn| 国产乱辈通伦影片在线播放亚洲| 最新久久免费视频| 91亚洲一区二区在线观看不卡| 每天更新的免费av片在线观看| 亚洲专区一路线二| 永久免费bbbbbb视频| 美女羞羞免费视频网站| 国外亚洲成AV人片在线观看| 最近免费字幕中文大全| 久久精品国产亚洲AV大全| 国产男女爽爽爽爽爽免费视频| 国产亚洲福利在线视频| 免费一级毛片在线播放| 97国免费在线视频| 亚洲性色成人av天堂| 日本xxwwxxww在线视频免费| 四虎国产精品永免费| 亚洲天天在线日亚洲洲精| 久久电影网午夜鲁丝片免费| 黄网站色视频免费观看45分钟| 国产精品亚洲视频| 成人免费一级毛片在线播放视频| 国产精品亚洲lv粉色| 久久精品亚洲日本佐佐木明希| 黄色网址免费观看| 羞羞视频免费网站日本| 666精品国产精品亚洲| 宅男666在线永久免费观看| 国产成人一区二区三区视频免费| 亚洲一区欧洲一区| 永久亚洲成a人片777777| 无码专区永久免费AV网站| 免费国产污网站在线观看|