【微信小程序开发】自定义组件以及页面布局设计 )

news2025/5/26 0:16:04

【微信小程序开发】自定义组件以及页面布局设计

  • 1.创建自定义组件
  • 2...在tabs的wxml文件中定制组件模板
    • 2.1.js中定义组件的属性
    • 2.2.定义组件的相关事件
    • 2.3在其他页面引用组件
    • 2.4在使用组件的wxml页面中使用组件
    • 2.5定义属性值
  • 三。个人中心的实现

)

1.创建自定义组件

在这里插入图片描述
要新建component才可以使用组件
在这里插入图片描述
自动会生成4个文件,现在可以开始使用主件。

2…在tabs的wxml文件中定制组件模板

<!-- components/tabs/tabs.wxml -->
<!-- <text>components/tabs/tabs.wxml</text> -->
<view class="tabs">
    <view class="tabs_title">
        <view wx:for="{{tabList}}" wx:key="id" class="title_item  {{index==tabIndex?'item_active':''}}" bindtap="handleItemTap" data-index="{{index}}">
            <view style="margin-bottom:5rpx">{{item}}</view>
            <view style="width:30px" class="{{index==tabIndex?'item_active1':''}}"></view>
        </view>
    </view>
    <view class="tabs_content">
        <slot></slot>
    </view>
</view>

2.给模板设计样式

/* components/tabs/tabs.wxss */
.tabs {
  position: fixed;
  top: 0;
  width: 100%;
  background-color: #fff;
  z-index: 99;
  border-bottom: 1px solid #efefef;
  padding-bottom: 20rpx;
}

.tabs_title {
  /* width: 400rpx; */
  width: 90%;
  display: flex;
  font-size: 9pt;
  padding: 0 20rpx;
}

.title_item {
  color: #999;
  padding: 15rpx 0;
  display: flex;
  flex: 1;
  flex-flow: column nowrap;
  justify-content: center;
  align-items: center;
}

.item_active {
  /* color:#ED8137; */
  color: #000000;
  font-size: 11pt;
  font-weight: 800;
}

.item_active1 {
  /* color:#ED8137; */
  color: #000000;
  font-size: 11pt;
  font-weight: 800;
  border-bottom: 6rpx solid #333;
  border-radius: 2px;
}

2.1.js中定义组件的属性

properties: {
   tabList:Object
  },

2.2.定义组件的相关事件

methods: {
    handleItemTap(e){
      // 获取索引
      const {index} = e.currentTarget.dataset;
      // 触发 父组件的事件
      this.triggerEvent("tabsItemChange",{index})
      this.setData({
          tabIndex:index
      })
    }

2.3在其他页面引用组件

{
  "usingComponents": { "tabs":"/components/tabs/tabs"},
  "navigationBarTitleText": "会议"
}

2.4在使用组件的wxml页面中使用组件

<tabs tabList="{{tabs}}"  bindtabsItemChange="tabsItemChange">

2.5定义属性值

Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    tabs:['会议中','已完成','已取消','全部会议'],
    lists: [
      {
        'id': '1',
        'image': '/static/persons/1.jpg',
        'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
        'num':'304',
        'state':'进行中',
        'time': '10月09日 17:59',
        'address': '深圳市·南山区'
      },
      {
        'id': '1',
        'image': '/static/persons/2.jpg',
        'title': 'AI WORLD 2016世界人工智能大会',
        'num':'380',
        'state':'已结束',
        'time': '10月09日 17:39',
        'address': '北京市·朝阳区'
      },
      {
        'id': '1',
        'image': '/static/persons/3.jpg',
        'title': 'H100太空商业大会',
        'num':'500',
        'state':'进行中',
        'time': '10月09日 17:31',
        'address': '大连市'
      },
      {
        'id': '1',
        'image': '/static/persons/4.jpg',
        'title': '报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”',
        'num':'150',
        'state':'已结束',
        'time': '10月09日 17:21',
        'address': '北京市·朝阳区'
      },
      {
        'id': '1',
        'image': '/static/persons/5.jpg',
        'title': '新质生活 · 品质时代 2016消费升级创新大会',
        'num':'217',
        'state':'进行中',
        'time': '10月09日 16:59',
        'address': '北京市·朝阳区'
      }
    ],
    lists1: [
      {
        'id': '1',
        'image': '/static/persons/1.jpg',
        'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
        'num':'304',
        'state':'进行中',
        'time': '10月09日 17:59',
        'address': '深圳市·南山区'
      },
      {
        'id': '1',
        'image': '/static/persons/2.jpg',
        'title': 'AI WORLD 2016世界人工智能大会',
        'num':'380',
        'state':'已结束',
        'time': '10月09日 17:39',
        'address': '北京市·朝阳区'
      },
      {
        'id': '1',
        'image': '/static/persons/3.jpg',
        'title': 'H100太空商业大会',
        'num':'500',
        'state':'进行中',
        'time': '10月09日 17:31',
        'address': '大连市'
      }
    ],
    lists2: [
      {
        'id': '1',
        'image': '/static/persons/1.jpg',
        'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
        'num':'304',
        'state':'进行中',
        'time': '10月09日 17:59',
        'address': '深圳市·南山区'
      },
      {
        'id': '1',
        'image': '/static/persons/2.jpg',
        'title': 'AI WORLD 2016世界人工智能大会',
        'num':'380',
        'state':'已结束',
        'time': '10月09日 17:39',
        'address': '北京市·朝阳区'
      }
    ],
    lists3: [
      {
        'id': '1',
        'image': '/static/persons/1.jpg',
        'title': '对话产品总监 | 深圳·北京PM大会 【深度对话小米/京东/等产品总监】',
        'num':'304',
        'state':'进行中',
        'time': '10月09日 17:59',
        'address': '深圳市·南山区'
      },
      {
        'id': '1',
        'image': '/static/persons/2.jpg',
        'title': 'AI WORLD 2016世界人工智能大会',
        'num':'380',
        'state':'已结束',
        'time': '10月09日 17:39',
        'address': '北京市·朝阳区'
      },
      {
        'id': '1',
        'image': '/static/persons/3.jpg',
        'title': 'H100太空商业大会',
        'num':'500',
        'state':'进行中',
        'time': '10月09日 17:31',
        'address': '大连市'
      },
      {
        'id': '1',
        'image': '/static/persons/4.jpg',
        'title': '报名年度盛事,大咖云集!2016凤凰国际论坛邀您“与世界对话”',
        'num':'150',
        'state':'已结束',
        'time': '10月09日 17:21',
        'address': '北京市·朝阳区'
      },
      {
        'id': '1',
        'image': '/static/persons/5.jpg',
        'title': '新质生活 · 品质时代 2016消费升级创新大会',
        'num':'217',
        'state':'进行中',
        'time': '10月09日 16:59',
        'address': '北京市·朝阳区'
      }
    ]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 
  },
 
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
 
  },
 
  tabsItemChange(e){
      let tolists;
      if(e.detail.index==1){
          tolists = this.data.lists1;
      }else if(e.detail.index==2){
          tolists = this.data.lists2;
      }else{
          tolists = this.data.lists3;
      }
      this.setData({
          lists: tolists
      })
  }
})

在这里插入图片描述

三。个人中心的实现

wxml

<!--pages/ucenter/index/index.wxml-->
<view class="userInfo">
  <image class="userInfo-head" src="/static/persons/1.jpg"></image>
  <view class="userInfo-login">匿瘾</view>
  <text class="userInfo-set">修改></text>
</view>
 
<view class="cells">
  <view class="cell-items">
    <image src="/static/tabBar/sdk.png" class="cell-items-icon"></image>
    <text class="cell-items-title">我发布的会议</text>
    <view class="cell-items-num">1</view>
    <text class="cell-items-detail"></text>
  </view>
  <hr />
  <view class="cell-items">
    <image src="/static/tabBar/sdk.png" class="cell-items-icon"></image>
    <text class="cell-items-title">我主持的会议</text>
    <view class="cell-items-num">1</view>
    <text class="cell-items-detail"></text>
  </view>
</view>
<view class="cells">
  <view class="cell-items">
    <image src="/static/tabBar/coding.png" class="cell-items-icon"></image>
    <text class="cell-items-title">投票的会议</text>
    <view class="cell-items-num">2</view>
    <text class="cell-items-detail"></text>
  </view>
  <hr />
  <view class="cell-items">
    <image src="/static/tabBar/coding.png" class="cell-items-icon"></image>
    <text class="cell-items-title">未投票的会议</text>
    <view class="cell-items-num">2</view>
    <text class="cell-items-detail"></text>
  </view>
</view>
<view class="cells">
  <view class="cell-items">
    <image src="/static/tabBar/template.png" class="cell-items-icon"></image>
    <text class="cell-items-title">我参与的会议</text>
    <view class="cell-items-num">5</view>
    <text class="cell-items-detail"></text>
  </view>
  <hr />
  <view class="cell-items">
    <image src="/static/tabBar/template.png" class="cell-items-icon"></image>
    <text class="cell-items-title">我审核的会议</text>
    <view class="cell-items-num">4</view>
    <text class="cell-items-detail"></text>
  </view>
</view>
 
<view class="cells">
  <view class="cell-items">
    <image src="/static/tabBar/coding.png" class="cell-items-icon"></image>
    <text class="cell-items-title">消息</text>
  </view>
  <hr />
  <view class="cell-items">
    <image src="/static/tabBar/component.png" class="cell-items-icon"></image>
    <text class="cell-items-title">设置</text>
 
  </view>
</view>

wxss

/* pages/ucenter/index/index.wxss */
.userInfo{
  padding: 5px 0px 20px 10px;
  display: flex;
  align-items: center;
}
.userInfo-head{
  height: 80px;
  width: 80px;}
.userInfo-login{
  width: 245px;
  padding-left: 10px;
  font-weight: 700;
}
.userInfo-set{
  margin-right:20rpx ;
  color: rgb(196, 170, 56);
}
.cells{
  border-top: 8px solid rgb(238, 238, 238);
}
.cell-items{
  
  display: flex;
  align-items: center;
  border-top: 1px solid rgb(238, 238, 238);
  padding-top: 20px;
  padding-bottom: 20px;
}
.cell-items-icon{
  height: 25px;
  width: 25px;
  padding: 0px 10px 0px 5px;![在这里插入图片描述](https://img-blog.csdnimg.cn/ce60b409eeb14b97b8e19d020777df83.png#pic_center)

}
.cell-items-title{
  width: 340px;
}
.cell-items-num{
  width: 30px;
  font-weight: 700;
  color: rgb(218, 31, 31);
}
.cell-items-detail{
  color: rgb(146, 151, 155);
}

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1114846.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

加密货币恐怖融资惊动国会!而链上分析公司看不下去了,紧急辟谣?

巴以冲突发生后&#xff0c;关于以加密货币资助恐怖分子的争论不断。全球最大的交易所币安和稳定币发行商Tether都表示己配合冻结多个账户和地址&#xff0c;以切断哈玛斯加密金援。美国合规交易所Coinbase也在近日发表了防止加密货币非法活动的宣言&#xff0c;反加密出名的参…

Mysql第二篇---InnoDB数据存储结构

Mysql第二篇—InnoDB数据存储结构 数据库的存储结构: 页 索引结构给我们提供了高效的索引方式, 不过索引信息以及数据记录都是保存在文件上的(innodb的ibd文件, MyISAM的MyI和MyD文件), 确切的说是存储在页结构中. 另一方面, 索引是在存储引擎中实现的, MySQL服务器上的存储引…

M-BUS和modbus的区别是什么?

M-BUS与Modbus是两种在工业自动化和楼宇自动化领域广泛应用的通信协议。那么&#xff0c;这两种通信协议有哪些区别呢?下面&#xff0c;就由小编带大家一起来了解下吧! 一、简介 M-BUS(Multi-dropBus&#xff0c;多点通信总线)和Modbus(莫迪波特率)都是用于设备和系统之间通信…

Python清理数据的常用方法总结

目录 1、数据预览 2、缺失值处理 3、异常值处理 4、数据类型转换 5、重复值处理 6、数据标准化 7、特征选择 8、处理类别数据 总结 在数据科学和机器学习领域&#xff0c;数据清理是一个非常重要的步骤。未经清理的数据可能会包含许多问题&#xff0c;例如缺失值、异常…

C++中多态的使用和建立条件

一、多态引入 多态按字面的意思就是多种形态。当类之间存在层次结构&#xff0c;并且类之间是通过继承关联时&#xff0c;就会用到多态。 C 多态意味着调用成员函数时&#xff0c;会根据调用函数的对象的类型来执行不同的函数。 根据代码&#xff0c;引入多态的概念&#xff1…

智能台灯语音控制丨解放双手

台灯是日常生活中一种常见的照明产品。以往的台灯大多都是采取手动控制&#xff0c;通过按键去对台灯的亮度进行调整。随着科技的发展&#xff0c;台灯也开始走向了智能化。人们已经能够对智能台灯进行语音控制&#xff0c;通过调节灯光开关、色温、灯光亮度等操作&#xff0c;…

代码随想录Day24 LeetCode T491 递增子序列 LeetCode T46 全排列 LrrtCode T47 全排列II

LeetCode T491 递增子序列 题目链接:491. 递增子序列 - 力扣&#xff08;LeetCode&#xff09; 题目思路: 首先这里的测试用例很容易误导我们,这道题不能使用上次子集的思路对数组先排序,使用一个used数组来解决问题. 我们用[4,7,6,7]举例这道题的递增序列不存在[4,6,7,7]这个…

“In Global,For China”,许战海咨询LOGO全面焕新

许战海咨询LOGO全面焕新&#xff0c;正式开启全球化战略! 作为一家起源于中国的全球性战略咨询公司&#xff0c;全新LOGO展现许战海咨询国际化企业形象&#xff0c;诠释出许战海咨询最新、最前沿的战略咨询理念“In Global&#xff0c;For China”(在全球&#xff0c;为中国)。…

CCF CSP认证 历年题目自练Day36

题目一 试题编号&#xff1a; 202309-1 试题名称&#xff1a; 坐标变换&#xff08;其一&#xff09; 时间限制&#xff1a; 1.0s 内存限制&#xff1a; 512.0MB 问题描述&#xff1a; 问题描述 对于平面直角坐标系上的坐标 (x,y)&#xff0c;小 P 定义了一个包含 n 个操作的…

SOFAStack软件供应链安全产品解析——SCA软件成分分析

近年来&#xff0c;软件供应链安全相关攻击事件呈快速增长态势&#xff0c;造成的危害也越来越严重&#xff0c;为了保障软件供应链安全&#xff0c;各行业主管单位也出台了诸多政策及技术标准。基于内部多年的实践&#xff0c;蚂蚁数科金融级云原生PaaS平台SOFAStack发布完整的…

搞一个生成modbus报文的CRC校验码的可视化工具

用python搞个可视化界面&#xff1a; # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QPushButton, QMessageBox# 生成 Modbus 格式的 CRC 校验码 def crc16_modbus(data):crc 0xFFFFfor byte in data:crc …

C++类和对象(二)(类对象的存储方式)

类对象模型 1 如何计算类对象的大小 class A { public: void PrintA() {cout<<_a<<endl; } private: char _a; }; 问题&#xff1a;类中既可以有成员变量&#xff0c;又可以有成员函数&#xff0c;那么一个类的对象中包含了什么&#xff1f;如何计算一个类的大小&…

混淆矩阵绘制

import numpy as np import matplotlib.pyplot as plt from sklearn.metrics import confusion_matrix# 示例的真实标签和预测标签 true_labels [cat, dog, bird, cat, dog, bird, cat, bird, bird] predicted_labels [cat, bird, dog, cat, bird, dog, cat, cat, bird]# 确定…

vue elementUI form组件动态添加el-form-item并且动态添加rules必填项校验方法

vue elementUI form组件动态添加el-form-item并且动态添加rules必填项校验方法 先看一下效果图&#xff08;想在表单里动态的增删 form-item&#xff0c;然后添加rules&#xff0c;校验其必填项&#xff1b; &#xff09;: html部分 <div v-for"(item, index) in …

Spring创建复杂对象

目录 一、什么是复杂对象 二、创建复杂对象的3种方式 2.1 实现FactoryBean接口 2.1.1 普通的创建方式 2.1.1 依赖注入的方式 2.1.3 FactoryBean的工作原理 2.2 实例工厂 2.3 静态工厂 一、什么是复杂对象 书接上回&#xff0c;我们已经分析了Spring是怎么去创建对象的了。那什…

【公众号开发】访问第三方接口应用于开发 · 回复图文消息

【公众号开发】&#xff08;2&#xff09; 文章目录 【公众号开发】&#xff08;2&#xff09;1. 第三方接口1.1 申请免费接口1.2 解读接口文档1.3 postman测试接口1.4 公众号开发访问第三方接口原理1.5 访问第三方接口示例1.5.1 引入依赖1.5.2 获取form格式的body字符串的方法…

EPLAN_005#宏边框、页宏、窗口宏/符号宏

一、宏边框 红边框不能用&#xff0c;变成了灰色 要在项目属性中更改位宏项目——才能使用宏边框功能 注意&#xff1a;创建宏边框时候要打开——显示隐藏元素 框选目标后&#xff0c;双击红边框的边——弹出红边框创建属性对话框——输入名称——更改变量ABC等 最后——自动…

10个设计人士应该关注的国内外资源网站

设计师网站1&#xff1a;即时设计 即时设计内拥有上万款来自于优秀设计师的精美设计作品&#xff0c;包括设计规范、页面、插画、图标、产品原型、作品集等等&#xff0c;这些作品往往都是由大厂团队精心总结的设计规范&#xff0c;对应着完善的设计系统与配套组件库。除此之外…

innoDB如何解决幻读

Mysql的事务隔离级别 Mysql 有四种事务隔离级别&#xff0c;这四种隔离级别代表当存在多个事务并发冲突时&#xff0c;可能出现的脏读、不可重复读、幻读的问题。其中 InnoDB 在 RR 的隔离级别下&#xff0c;解决了幻读的问题 事务隔离级别脏读不可重复读幻读未提交读&#xff…

openEuler 服务器安装 JumpServer (all-in-one 模式)

openEuler 服务器安装 JumpServer JumpServer 简介什么是 JumpServer &#xff1f;JumpServer 的各种类型资产JumpServer 产品特色或优势JumpServer 符合 4A 规范 JumpServer 系统架构应用架构组件说明 JumpServer 安装部署环境要求网络端口网络端口列表防火墙常用命令 在线脚本…