本篇文章给大家带来的内容是关于小程序自定义组件的实现方法(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
File:threecolgrid.js
// components/threeColumnGrid/threecolgrid.js Component({ /** * 组件的属性列表 */ properties: { // 传入的数据 booksData:{ type: Array, value:[] }, // grid的外边距 mainMargin:{ type: Number, value: 5 }, // grid的内边距 mainPadding:{ type:Number, value:10 }, // 行间距 rowSpace:{ type:Number, value:20 }, // 列间距 colSpace:{ type:Number, value:7 } }, /** * 组件的初始数据 */ data: { }, /** * 组件的方法列表 */ methods: { checkIn:function(e){ console.log(e.currentTarget.dataset) // 触发action事件,triggerEvent函数接受三个值:事件名称、数据、选项值 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; /* 调节图书列 */ /* 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; /* 调节图书列 */ /* 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; }
使用组件
//事件处理函数 getCheckValues: function(e){ console.log('checkbox发生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; */ }
相关推荐:
详解javascript实现自定义事件_javascript技巧
以上是小程序自定义组件的实现方法(代码)的详细内容。更多信息请关注PHP中文网其他相关文章!

html5的div元素默认一行不可以放两个。div是一个块级元素,一个元素会独占一行,两个div默认无法在同一行显示;但可以通过给div元素添加“display:inline;”样式,将其转为行内元素,就可以实现多个div在同一行显示了。

html5中列表和表格的区别:1、表格主要是用于显示数据的,而列表主要是用于给数据进行布局;2、表格是使用table标签配合tr、td、th等标签进行定义的,列表是利用li标签配合ol、ul等标签进行定义的。

固定方法:1、使用header标签定义文档头部内容,并添加“position:fixed;top:0;”样式让其固定不动;2、使用footer标签定义尾部内容,并添加“position: fixed;bottom: 0;”样式让其固定不动。

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

html5中不支持的标签有:1、acronym,用于定义首字母缩写,可用abbr替代;2、basefont,可利用css样式替代;3、applet,可用object替代;4、dir,定义目录列表,可用ul替代;5、big,定义大号文本等等。

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

html5是指超文本标记语言(HTML)的第五次重大修改,即第5代HTML。HTML5是Web中核心语言HTML的规范,用户使用任何手段进行网页浏览时看到的内容原本都是HTML格式的,在浏览器中通过一些技术处理将其转换成为了可识别的信息。HTML5由不同的技术构成,其在互联网中得到了非常广泛的应用,提供更多增强网络应用的标准机。

3种取消方法:1、给td元素添加“border:none”无边框样式即可,语法“td{border:none}”。2、给td元素添加“border:0”样式,语法“td{border:0;}”,将td边框的宽度设置为0即可。3、给td元素添加“border:transparent”样式,语法“td{border:transparent;}”,将td边框的颜色设置为透明即可。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

记事本++7.3.1
好用且免费的代码编辑器

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

Dreamweaver CS6
视觉化网页开发工具