• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當前位置:雨林木風下載站 > 應用軟件教程 > 詳細頁面

        小程序自定義組件的完成方法(代碼)

        小程序自定義組件的完成方法(代碼)

        更新時間:2025-09-20 文章作者:未知 信息來源:網(wǎng)絡 閱讀次數(shù):

        微信小程序,簡稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應用,它實現(xiàn)了應用“觸手可及”的夢想,用戶掃一掃或搜一下即可打開應用。小程序是一種不用下載就能使用的應用,也是一...
        微信小程序,簡稱小程序,英文名Mini Program,是一種不需要下載安裝即可使用的應用,它實現(xiàn)了應用“觸手可及”的夢想,用戶掃一掃或搜一下即可打開應用。小程序是一種不用下載就能使用的應用,也是一項門檻非常高的創(chuàng)新,經(jīng)過將近兩年的發(fā)展,已經(jīng)構造了新的小程序開發(fā)環(huán)境和開發(fā)者生態(tài)。
        本篇文章給大家?guī)淼膬?nèi)容是關于小程序自定義組件的實現(xiàn)方法(代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

        2114713864-5b9b3b8856d4e_articlex.png
        File:threecolgrid.js

        // components/threeColumnGrid/threecolgrid.js
        Component({
          /**
           * 組件的屬性列表
           */
          properties: {
            // 傳入的數(shù)據(jù)
            booksData:{
              type: Array,
              value:[]
            },
            // grid的外邊距
            mainMargin:{
              type: Number,
              value: 5
            },
            // grid的內(nèi)邊距
            mainPadding:{
              type:Number,
              value:10
            },
            // 行間距
            rowSpace:{
              type:Number,
              value:20
            },
            // 列間距
            colSpace:{
              type:Number,
              value:7
            }
          },
        
          /**
           * 組件的初始數(shù)據(jù)
           */
          data: {
        
          },
        
          /**
           * 組件的方法列表
           */
          methods: {
            checkIn:function(e){
              console.log(e.currentTarget.dataset)
              // 觸發(fā)action事件,triggerEvent函數(shù)接受三個值:事件名稱、數(shù)據(jù)、選項值  
              this.triggerEvent('action', e.currentTarget.dataset, {}) 
            }
          }
        })
        <!--components/threeColumnGrid/threecolgrid.wxml-->
        <!-- <view class='main-content'> -->
          <view class='bookbox' style='padding:{{mainPadding}}rpx;margin:{{mainMargin}}rpx;'>
            <block wx:for="{{booksData}}" wx:key="{{item.id}}">
              <view class='bookinfo' style='margin-bottom: {{rowSpace}}rpx;'>
                <image src='{{item.url}}' mode="widthFix" style='width:{{(740 - 2*mainPadding - 2*mainMargin)/3 - colSpace*3}}rpx;'></image>
                <view class="title" style='width:{{(740 - 2*mainPadding - 2*mainMargin)/3 - colSpace*3}}rpx;'>{{item.title}}</view>
                <view class='actionBar' style='width:{{(740 - 2*mainPadding - 2*mainMargin)/3 - colSpace*3}}rpx;'>
                  <block wx:if="{{item.status == 0}}">
                    <view class='bookstatus disable'>暫缺貨</view>
                    <view bindtap='checkIn' data-bookid='{{item.id}}' data-status='{{item.status}}' class='iconfont icon-219-heart icon'></view>
                  </block>
                  <block wx:else>
                    <view class='bookstatus enable'>可借閱</view>
                    <view bindtap='checkIn' data-bookid='{{item.id}}' data-status='{{item.status}}' class='iconfont icon-059-cart icon'></view>
                  </block>          
                </view>
              </view>
            </block>
          </view>
        <!-- </view> -->
        /* components/threeColumnGrid/threecolgrid.wxss */
        @import "../../iconfont.wxss";
        /* .main-content{
          background: #FFF;
          margin-top: 155rpx;
          padding:10rpx;
        } */
        
        .bookbox{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          flex-wrap:wrap;
          background: #FFF;
        }
        .bookbox .bookinfo{
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          /* border: 1rpx solid #f5a32d; */
        }
        .bookbox .bookinfo image{
          display: flex;
          /* 調(diào)節(jié)圖書列 */
          /* width:220rpx;  */
          border-top-left-radius: 10rpx;
          border-top-right-radius: 10rpx
        }
        .bookbox .bookinfo .title{
          display: flex;
          flex-wrap: wrap;
          font-size: small;
          margin-bottom: 5rpx;
          /* 調(diào)節(jié)圖書列 */
          /* width:300rpx; */
          /* width:220rpx; */
          height: 70rpx;
        }
        .bookbox .bookinfo .actionBar{
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 0rpx 5rpx 5rpx 5rpx;
          font-size: smaller;
          /* width:200rpx; */
        }
        
        .bookbox .bookinfo .actionBar .bookstatus{
          display: flex;
          border-radius: 10rpx;
          padding:0rpx 5rpx;
        }
        
        .bookbox .bookinfo .actionBar .enable{
          color: #FFF;
          background-color: #f5a32d;
        }
        
        .bookbox .bookinfo .actionBar .disable{
          color: #FFF;
          background-color: #727171;
        }
        
        .bookbox .bookinfo .actionBar .icon{
          font-size: 15pt;
          color: #facea7;
        }
        
        .bookinfo-empty{
          display: flex;
          flex-direction: column;
          align-items: center;
          padding: 5rpx;
          width:230rpx;
        }

        使用組件

          //事件處理函數(shù)
          getCheckValues: function(e){
            console.log('checkbox發(fā)生change事件,攜帶value值為:', e.detail)
          },
        {
        
          "usingComponents": {
            "three-col-grid":"/components/threeColumnGrid/threecolgrid"
          },
        
        }
          <view class='test'>
            <three-col-grid booksData="{{BookList}}" bind:action="getCheckValues"></three-col-grid>
          </view>
        .test{
          display: flex;
          justify-content: center;
          /* border: 1rpx #444 solid; */
        }

        相關推薦:

        php實現(xiàn)Mongodb自定義方式生成自增ID的方法

        詳解javascript實現(xiàn)自定義事件_javascript技巧

        以上就是小程序自定義組件的實現(xiàn)方法(代碼)的詳細內(nèi)容,更多請關注php中文網(wǎng)其它相關文章!


        小程序是一種不需要下載安裝即可使用的應用,它實現(xiàn)了應用“觸手可及”的夢想,用戶掃一掃或者搜一下即可打開應用。

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統(tǒng)下載排行

        主站蜘蛛池模板: 亚洲国产精品成人精品无码区在线| 日韩高清免费在线观看| 亚洲国产小视频精品久久久三级 | 中文字幕无码免费久久9一区9| 成人A级毛片免费观看AV网站| 亚洲天堂一区二区三区四区| 亚洲小视频在线播放| 无码国产精品一区二区免费模式| 亚洲人成网站在线播放vr| 91国内免费在线视频| 亚洲欧洲精品无码AV| 精品四虎免费观看国产高清午夜| 亚洲av永久无码精品国产精品| 亚洲精品无码久久久久牙蜜区| 热99re久久免费视精品频软件| 伊伊人成亚洲综合人网7777| 亚洲人成人网毛片在线播放| 99在线免费视频| 亚洲av无码一区二区三区不卡| 久久永久免费人妻精品下载| jjzz亚洲亚洲女人| www.亚洲日本| 亚洲一区二区在线免费观看| 亚洲色大成网站www永久| 国产在线精品免费aaa片| 亚洲永久中文字幕在线| 噼里啪啦电影在线观看免费高清 | 国产产在线精品亚洲AAVV| 亚洲精品国产高清不卡在线| 免费无码黄网站在线看| 亚洲嫩草影院在线观看| 国产免费人成视频在线观看| a国产成人免费视频| 亚洲一区在线观看视频| 最近2019免费中文字幕视频三| 黑人大战亚洲人精品一区| 国产午夜无码精品免费看| 亚洲粉嫩美白在线| 国产亚洲精aa成人网站| 成人自慰女黄网站免费大全| 亚洲成年人电影在线观看|