当前位置:网站首页>微信小程序 自定义 弹框组件
微信小程序 自定义 弹框组件
2022-06-26 18:10:00 【RosaChampagne】
效果图:

<!--components/popup/popup.wxml-->
<view class="popup" hidden="{
{flag}}">
<view class='popup-container'>
<view wx:if="{
{title}}" class="popup-title">{
{title}}</view>
<view>
</view>
<view class="popup-con">
<image src="{
{image}}" />
<view>{
{content}}</view>
</view>
<view class="popup-btn">
<text class="btn-no" bindtap='_error'>{
{btn_no}}</text>
<text class="btn-ok" bindtap='_success'>{
{btn_ok}}</text>
</view>
</view>
</view>// components/popup/popup.js
Component({
/**
* Component properties
*/
properties: {
title: { // 属性名
type: String, // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
value: '' // 属性初始值(可选),如果未指定则会根据类型选择一个
},
// 弹窗图片
image: {
type: String,
value: ''
},
// 弹窗内容
content: {
type: String,
value: ''
},
// 弹窗取消按钮文字
btn_no: {
type: String,
value: '取消'
},
// 弹窗确认按钮文字
btn_ok: {
type: String,
value: '确定'
}
},
/**
* Component initial data
*/
data: {
flag: true,
},
/**
* Component methods
*/
methods: {
//隐藏弹框
hidePopup: function () {
this.setData({
flag: !this.data.flag
})
},
//展示弹框
showPopup () {
this.setData({
flag: !this.data.flag
})
},
/*
* 内部私有方法建议以下划线开头
* triggerEvent 用于触发事件
*/
_error () {
//触发取消回调
this.triggerEvent("error")
},
_success () {
//触发成功回调
this.triggerEvent("success");
}
}
})
{
"component": true
}/* components/popup/popup.wxss */
.popup {
z-index: 9;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .5);
}
.popup-container {
position: absolute;
left: 50%;
top: 50%;
width: 80%;
max-width: 600rpx;
border: 2rpx solid #ccc;
border-radius: 20rpx;
box-sizing: bordre-box;
transform: translate(-50%, -50%);
overflow: hidden;
background: rgba(250,250,250,1);
}
.popup-title {
width: 100%;
padding: 20rpx;
text-align: center;
font-size: 40rpx;
border-bottom: 2rpx solid red;
}
.popup-con {
margin: 36rpx 10rpx;
text-align: center;
}
.popup-con image {
width: 196rpx;
height: 196rpx;
}
.popup-btn {
display: flex;
justify-content: space-around;
}
.popup-btn text {
display: flex;
align-items: center;
justify-content: center;
width: 50%;
height: 106rpx;
border-top: 2rpx solid #EDEDED;
}
.popup-btn .btn-no {
border-right: 2rpx solid #EDEDED;
} <popup id='popup'
image='../../images/organizer/application-success.png'
content='申请成功'
btn_no='立即发起活动'
btn_ok='成为认证用户'
bind:error="_error"
bind:success="_success">
</popup>
onReady: function (options) {
//获得popup组件
this.popup = this.selectComponent("#popup");
},
showPopup() {
this.popup.showPopup();
},
//取消事件
_error() {
console.log('你点击了取消');
this.popup.hidePopup();
},
//确认事件
_success() {
console.log('你点击了确定');
this.popup.hidePopup();
},
边栏推荐
- sqlite数据库的系统表sqlite_master
- 深入理解MySQL锁与事务隔离级别
- 17.13 supplementary knowledge, thread pool discussion, quantity discussion and summary
- Conditional compilation in precompiling instructions
- 成功解决之idea引用Lombok的@Slf4j后无法正常使用log
- (multi threading knowledge points that must be mastered) understand threads, create threads, common methods and properties of using threads, and the meaning of thread state and state transition
- Chinese (Simplified) language pack
- 如何创建并强制使用索引
- tag动态规划-刷题预备知识-2. 0-1背包理论基础和二维数组解法模板
- 数据加密标准(DES)概念及工作原理
猜你喜欢

Clion breakpoint single step debugging

MySQL的MVCC机制详解

Clion编译catkin_ws(ROS工作空间包的简称)加载CMakeLists.txt出现的问题

next(iter(dataloader))的一点点体会

数字签名论述及生成与优点分析

Runtimeerror: CUDA error: out of memory own solution (it is estimated that it is not applicable to most people in special circumstances)

50行代码爬取Top500图书导入TXT文档

properties文件乱码

(multi threading knowledge points that must be mastered) understand threads, create threads, common methods and properties of using threads, and the meaning of thread state and state transition

JVM入个门(1)
随机推荐
(必须掌握的多线程知识点)认识线程,创建线程,使用Thread的常见方法及属性,以及线程的状态和状态转移的意义
Temporarily turn off MySQL cache
行锁与隔离级别案例分析
数据加密标准(DES)概念及工作原理
transforms.RandomCrop()的输入只能是PIL image 不能是tensor
RSA概念详解及工具推荐大全 - lmn
How to create and enforce indexes
Please advise tonghuashun which securities firm to choose for opening an account? Is it safe to open an account online now?
Do you know how to compare two objects
ZCMU--1367: Data Structure
输入n个整数,输出出现次数大于等于数组长度一半的数
pycharm的plt.show()如何保持不关闭
CD-CompactDisk
Leetcode 128 longest continuous sequence
如何创建并强制使用索引
Lm06 the mystery of constructing the bottom and top trading strategy only by trading volume
成功解决之idea引用Lombok的@Slf4j后无法正常使用log
IDEA收藏代码、快速打开favorites收藏窗口
Padding percentage operation
VCD-影音光碟