微信小程序UI之旅:标签流组件的简单实现

效果图

微信小程序UI之旅:标签流组件的简单实现_第1张图片
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

自定义属性和方法

属性 描述
src 数据源(数组)
方法 描述
labeltap 标签点击监听

使用示例


   

.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"
  }
}

源码

  • ab-label-flow.wxml

  
    {{item.name}}
  

  • ab-label-flow.wxss
.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;
}
  • ab-label-flow.js
Component({
  options: {
    multipleSlots: true 
  },

  properties: {
    // 数据源
    src: {
      type: Array
    }
  },

  methods: {
    /**
     * 标签点击监听
     */
    _labelTap: function(e) {
      this.triggerEvent('labeltap', e.currentTarget);
    }
  }
})
  • ab-label-flow.json
{
  "component": true,
  "usingComponents": {}
}

你可能感兴趣的:(微信小程序UI之旅:标签流组件的简单实现)