小程序开发之组件的使用
<view wx:if="{{state}}" class='drop-bot' bindtap='closer'><view scroll-y="true" class="box {{first_click?'show':'hide'}} {{state?'open':'close'}}"><view style='height: 100%;' class="item_list"><scroll-view class='scroll' scroll-y="true" style='height: 275rpx'><view wx:for="{{account}}" wx:key="{{index}}" class=' li {{style}}' data-index="{{index}}" catchtap='select'>{{item.name}} </view></scroll-view><view class='li' catchtap='closer'>取消</view></view></view>
</view>
/* 下拉框的实现 */
.drop-bot {width: 100%;height: 100%;position: fixed;bottom: 0;left: 0;background: rgba(0, 0, 0, .4);z-index: 1000;
}
.drop-bot .box{width: 100%;border-top: 1px solid #ddd;overflow: hidden;height: 0;animation-fill-mode: forwards;position: fixed;bottom: 0;left: 0;font-family: Monaco;">#fff;
}
.item_list .li.style {font-family: Monaco;">#f1f1f1;
}
.item_list .li{width: 100%;height: 90rpx;line-height: 90rpx;overflow: auto;white-space: nowrap;display: flex;justify-content: center;align-items: center;border-bottom: 1rpx solid #ebebeb;
}
@keyframes slidedown{from {height: 0;}to {height: 365rpx;}
}
@keyframes slideup{from {height: 365rpx;}to {height: 0;}
}
.open{animation: slidedown .5s;
}
.close{animation: slideup .5s;
}
.hide{display: none;
}
.show{display: block;
}
{"component": true,"usingComponents": {}
}
// 弹出框组件
Component({
/**
* 组件的属性列表
*/
properties: {account: {type: Array,value: []},accountName: {type: String,value: ""}
},//存放公共数据的地方,可以供调用方传递数据/**
* 组件的初始数据
*/
data: {state: false,first_click: false,
},//私有属性的地方,data中的数据只有组件可以访问,外部无法访问/**
* 组件的方法列表
*/
methods: {closer: function (e) {this.setData({state: false,})},//点击遮罩层消失select: function (e) {var oIndex = e.currentTarget.dataset.index;var oAccount = this.data.account[oIndex].name;//这里需要的数据有调用方传递到propertiesthis.setData({state: false,})this.triggerEvent("action",oAccount);//将该方法抛出},//选择下拉的用户名称toggle: function () {var list_state = this.data.state,first_state = this.data.first_click;if (!first_state) {this.setData({first_click: true});}if (list_state) {this.setData({state: false});} else {this.setData({state: true});}},//调出弹出框事件
}//存放事件的地方
})
<!-- 触发下拉事件的按钮 -->
<view class='header' bindtap="toggle"><text>{{accouontName}}</text><text>切换</text></view>
<!-- 组件:下拉弹出框 -->
<template-dialog id="dialog" account="{{account}}" accountName="{{accountName}}" bind:action="switchAccount"></template-dialog>
.header {width: 100%;height: 90rpx;padding: 0 24rpx;box-sizing: border-box;font-family: Monaco; font-size: 11pt;">#16cc80;display: flex;justify-content: space-around;align-items: center;
}
{"usingComponents": {"template-dialog": "/components/dialog/dialog"}
}
Page({data: {accountName: "",account: [{ "name": "李小冉" },{ "name": "李冰" },{ "name": "李浩然" },{ "name": "李宗盛" },],},onReady: function (e) {this.dialog = this.selectComponent("#dialog");//通过给组件所起的id调用组件},toggle: function (e) {this.dialog.toggle()}, //给头部添加的调出下拉框的事件switchAccount: function (options) {this.setData({accountName: options.detail})}, //组件内部的方法将options传递过来的数据使用上
})
转载于:https://www.cnblogs.com/bgwhite/p/9272796.html
小程序开发之组件的使用相关推荐
- 微信小程序开发:组件
文章目录 小程序中组件的分类 常用的视图容器组件 view组件的基本使用 scroll-view组件的基本使用 swiper组件 常用的基础内容组件 button按钮的基本使用 image组件的基本使 ...
- 小程序开发 - 基本组件
目录 小程序启动过程 页面渲染过程 新建文件夹 组件 view scroll-view swiper和swiper-item button image 小程序启动过程 将小程序代码包下载本地 解析ap ...
- 四十八、微信小程序开发系统组件
@Author:Runsen Hello,现在中午,结果写完到了下午.还是再复习学习下小程序的组件,以后开发项目就有了强大的基础.来吧,不学习就是辣鸡. 文章目录 组件 scroll-view swi ...
- 微信小程序开发之组件official-account(配置公众号关注组件)
official-account 基础库 2.3.0 开始支持 作用:公众号关注组件.当用户扫小程序码打开小程序时,开发者可在小程序内配置公众号关注组件,方便用户快捷关注公众号,可嵌套在原生组件内. ...
- [转]小程序开发之组件ad(广告)(转载请删除括号里的内容)
ad 广告.目前暂时以邀请制开放申请,请留意后续模板消息的通知 注1:监听到error回调后,开发者可以针对性的处理,比如隐藏广告组件的父容器,以保证用户体验,但不要移除广告组件,否则将无法收到bin ...
- 微信小程序开发——switch组件
WeChat小程序交流(QQ群:769977169) 效果图 代码示例 1.xxx.wxml <switch bindchange='switchClick'>{{switchTitle} ...
- 小程序开发之组件video(视频)
video 视频.该组件是原生组件,使用时请注意相关限制. 默认宽度300px.高度225px,可通过wxss设置宽高. 例如: 效果展示 代码 index.wxml <!-- src 要播放视 ...
- 小程序确定取消弹窗_小程序开发之弹出框
小程序开发过程中,很多地方为了便利我们多采用小程序自带弹出框来实现交互效果.这也够大多数开发使用,下面我给大家详细介绍下小程序弹出框 wx.showToast() title:显示的提示信息,在没有图 ...
- 小程序开发之各种弹出框选择框汇总
小程序开发过程中,很多地方为了便利我们多采用小程序自带弹出框来实现交互效果.这也够大多数开发使用,下面我给大家详细介绍下小程序弹出框 官方api传送门:https://developers.weixi ...
最新文章
- java常用的集合对象_java常用实体类、集合类
- VM创建虚拟机及安装Centos7
- 自动化才能解放安全团队
- Model和ViewModel
- SMS短信的C语言代码摘抄
- 最终选型 Blazor.Server:又快又稳!
- linux多线程 pthread用法
- 基于java的数据结构学习——数组实现的队列和循环队列及性能对比
- mysql忘记密码找回密码_MySQL忘记密码找回 重置MySQL root用户密码
- dbvisivuser连oracle数据库报错没有权限
- 删除word文档中的空白页
- 计算机ps图片在哪里看,怎么看图片有没有PS 两种查看照片有没被PS过的方法-电脑教程...
- 用 StarRocks on ES 实现 分词
- 【WIN10安装】拒绝第三方软件,纯净官网系统,U盘安装教程
- Hololens2,隐藏着微软真正的野心!
- Chromedriver插件的安装
- 2834: 小凯的书架
- 1. jack-server报错
- (数字图像处理MATLAB+Python)第四章图像正交变换-第一节:离散傅里叶变换
- Atitit mis 管理信息系统概论 艾提拉著 目录 1. 互联网三大定律	2 1.1. 摩尔定律和	2 1.2. 吉尔德定律 电脑及网络宽带资源成为重要免费资源	2 1.3. 梅特卡夫定律 用户