效果图
image.png
github传送门:https://github.com/albert-lii/wx-abui/tree/master/abui/widgets/ab-label-flow
demo传送门:https://github.com/albert-lii/wx-abui/tree/master/pages/mainex
自定义属性和方法
使用示例
<view class="container">
<ab-label-flow class="label-flow" src="{{labels}}" bindlabeltap="labelTap"/>
</view>
.label-flow {
margin-top: 30rpx;
background: tan;
padding-top: 18rpx;
padding-left: 20rpx;
}
const LABEL_SOURCE = require('../../utils/label_flow_source.js');
Page({
data: {
labels: LABEL_SOURCE.labels
},
/**
* 标签点击监听
*/
labelTap: function (e) {
wx.showToast({
icon: 'none',
title: e.detail.dataset.item.name,
duration: 1200
});
}
})
{
"navigationBarTitleText": "abui",
"usingComponents": {
"ab-label-flow": "../../abui/widgets/ab-label-flow/ab-label-flow"
}
}
源码
<view class="label">
<view class="label-item" wx:for="{{src}}" wx:for-index="index" wx:for-item="item" wx:key="{{index}}" hover-class="label-item__hover" hover-stay-time="100" bindtap="_labelTap" data-index="{{index}}" data-item="{{item}}">
{{item.name}}
</view>
</view>
.label {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: start;
width: 100%;
}
.label-item {
position: relative;
height: 51rpx;
line-height: 51rpx;
padding-left: 21rpx;
padding-right: 21rpx;
margin-right: 20rpx;
margin-bottom: 18rpx;
font-size: 25rpx;
color: #2e2e2e;
text-align: center;
background-color: white;
border-radius: 4px;
}
.label-item__hover {
color: white;
background-color: #2e2e2e;
}
Component({
options: {
multipleSlots: true
},
properties: {
// 数据源
src: {
type: Array
}
},
methods: {
/**
* 标签点击监听
*/
_labelTap: function(e) {
this.triggerEvent('labeltap', e.currentTarget);
}
}
})
{
"component": true,
"usingComponents": {}
}
网友评论