微信小程序 自定义弹框组件

article/2025/9/21 8:51:53

话不多说直接上代码

目录

1、wxml

2、js

3、wxss

4、json

5、效果展示(具体内容可以自定义)


1、wxml

<!--pages/components/confirmBox/confirmBox.wxml-->
<wxs src="../../../filter/urlFilter.wxs" module="filter" />
<view class="confirmBox_warp" style="{{opt.wrapStyle}}" wx:if="{{isShow}}"><view class="count" style="width:{{opt.widths?opt.widths:'600'}}rpx"><view style="" class="paddClass {{opt.showCancel || opt.showConfirm? 'paddingNo': ''}}"><!-- 关闭按钮 --><view class="confirm_close_cont" bindtap="closeConfirm" wx:if="{{!opt.close}}"><image  class="confirm_close" mode="widthFix" bindtap="hide" src="{{filter.imgFullPath('/images/icon-close.png')}}"></image></view><!-- header --><view class="headers" style="{{opt.headerStyle}}" wx:if="{{opt.header}}">{{opt.header}}</view><view class="body"><slot name="top"></slot><slot name="center"></slot><slot name="bottom"></slot></view></view><view class="footer" style="{{opt.footerStyle}}" wx:if="{{opt.showCancel || opt.showConfirm}}"><view class="li" wx:if="{{opt.showCancel && !opt.showCancelContact}}" bindtap="cancelCb" style="{{opt.cancelStyle}}">{{opt.cancelText}}</view><view class="li" wx:if="{{opt.showCancelContact}}"  style="{{opt.cancelStyle}}"><button class="contactBtn" open-type="contact">{{opt.cancelText}}</button></view><view class="li" wx:if="{{opt.showConfirm && !opt.showConfirmContact}}" bindtap="confirmCb" style="{{opt.confirmStyle}}">{{opt.confirmText}}</view><view class="li" wx:if="{{opt.showConfirmContact}}"  style="{{opt.confirmStyle}}"><button class="contactBtn" open-type="contact">{{opt.confirmText}}</button></view></view></view>
</view>

2、js

// pages/components/confirmBox/confirmBox.js
Component({options: {multipleSlots: true // 允许使用插槽},/*** 组件的属性列表*/properties: {isShow:{type:Boolean,value:false},opt:{type:Object,value:{wrapStyle: '',widths:'',close:false, //默认显示关闭按钮header:'',showCancel: false,showCancelContact: false,showConfirmContact: false, showConfirm: false,cancelText: '取消',confirmText: '确定',confirmStyle: '',cancelStyle: ''},observer:function(newVal,oldVal){this.data.opt = {...oldVal,...newVal}this.setData({opt:this.data.opt})}}},/*** 组件的初始数据*/data: {},/*** 组件的方法列表*/methods: {closeConfirm:function (){this.setData({isShow:false})},cancelCb: function(){this.triggerEvent('cancelCb');},confirmCb:function(){this.triggerEvent('confirmCb');}}
})

3、wxss

/* pages/components/confirmBox/confirmBox.wxss */
.confirmBox_warp{position: fixed;top: 0rpx;left: 0rpx;height: 100%;width: 100%;background-color: rgba(0, 0, 0, 0.3);z-index: 11111111111199;
}
.confirmBox_warp .count{width: 600rpx;position: absolute;top: 50%;left: 50%;transform: translateX(-50%) translateY(-50%);background-color: #ffffff;border-radius: 16rpx;}
.confirmBox_warp .count .paddClass{padding: 60rpx 40rpx;
}
.confirmBox_warp .count .paddingNo {padding-bottom: 0;
}
.confirmBox_warp .count .confirm_close_cont{padding: 20rpx;position: absolute;top: 0rpx;right: 0rpx;
}
.confirmBox_warp .count .confirm_close{width: 21rpx;height: 21rpx;
}
.confirmBox_warp .count .headers{text-align: center;color: #333333;font-size: 32rpx;line-height: 44rpx;
}
.confirmBox_warp .footer {display: flex;justify-content: space-between;height: 100rpx;border-top: 0.5px solid #E3E3E3;margin-top: 20rpx;/* margin-bottom: 10rpx; */
}
.confirmBox_warp .footer .li {flex: 1;border-right: 0.5px solid #E3E3E3;text-align: center;line-height: 100rpx;color: #333333;font-size: 32rpx;
}
.confirmBox_warp .footer .li .contactBtn{background-color: #ffffff;text-align: center;line-height: 80rpx;padding: 0rpx;/* color: #FE4561; */font-size: 32rpx;font-weight: normal;    width: 100%;
}
.confirmBox_warp .footer .li:last-child {border: none;
}

4、json

{"component": true,"usingComponents": {}
}

5、效果展示(具体内容可以自定义)

可以参考--文章:微信小程序获取定位、通过地点文本获取经纬度进行导航


http://chatgpt.dhexx.cn/article/6gyajCM5.shtml

相关文章

微信小程序——点击某个按钮实现下面弹窗的出现

效果图:(真的是图) wxml(代码里面有解释&#xff09; <button type"primary" bindtap"Popup">点我</button> <!--点击后灰色背景的设置--> <view wx:if"{{now_state}}" class"background" bindtap"hideM…

微信小程序实现底部向上弹框

本文转自 作者&#xff1a;smallzip 链接&#xff1a;https://www.jianshu.com/p/bd9a4f4b8e6a 著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处。 效果 小程序自定义底部弹出modal框组件&#xff0c;仿照小程序sheet-action的效果&#xff0…

uniapp微信小程序的各种弹框提示(轻提示)

您直接复制粘贴即可使用不需要做特殊的处理。 如您满意请给莫成尘点个Fabulous 1&#xff1a; 纯文字提示框 uni.showToast({title: 只有文字弹窗,icon: none, //如果要纯文本&#xff0c;不要icon&#xff0c;将值设为noneduration: 2000 //持续时间为 2秒 }) 2&…

小程序实现弹出输入框

1.微信自带组件 样式&#xff1a; wxml <view class"close" bindtap"close">拒绝</view>js Page({//拒绝close(e) {wx.showModal({editable:true,//显示输入框placeholderText:输入拒绝原因,//显示输入框提示信息success: res > {if (re…

微信小程序提示弹窗大全

wx.showToast(OBJECT) 显示消息提示框 OBJECT参数说明&#xff1a; 示例代码&#xff1a; ? 1 2 3 4 5 wx.showToast({ title: 成功 , icon: success , duration: 2000 }) wx.hideToast() 隐藏消息提示框 ? 1 2 3 4 5 6 7 8 9 wx.showToast({ title: 加载中 , icon: lo…

微信小程序 四种弹窗方式

微信小程序弹窗 一、wx.showToast(Object object)二 、wx.showModal(Object object)三、wx.showLoading(Object object)四、wx.showActionSheet(Object object)五、官方文档 一、wx.showToast(Object object) 显示消息提示框 wx.showToast({title: 内容, //提示的内容duration…

微信小程序弹出框详解

[html] view plain copy <span style"font-family:Comic Sans MS;font-size:18px;color:#333333;"><view class"container" class"zn-uploadimg"> <button type"primary"bindtap"showok">消息提示…

微信小程序几种常用弹窗提示

第一种&#xff1a;弹出提示框&#xff0c;可以选择确定或者取消。 代码&#xff1a;wx.showModal({title: 提示,content: 这是一个模态弹窗,success: function (res) {if (res.confirm) {//这里是点击了确定以后console.log(用户点击确定)} else {//这里是点击了取消以后conso…

微信小程序几种常用弹窗提示方法

1.提示文字 可以设置显示时间&#xff08;仅提示时使用&#xff09;duration设置时间 不显示icon&#xff0c;此时 title文字最多可显示两行 也可以显示icon&#xff0c;显示icon文字最多显示 7 个汉字长度 icon常用的有&#xff1a;success、error、loading wx.showToast(…

微信小程序展示弹窗的方式

微信小程序中展示弹窗有四种方式&#xff1a;wx.showToast、wx.showModal、wx.showLoading、wx.showActionSheet 具体参数可参照微信开发文档 1. wx.showToast <!-- index.wxml --> <!-- wx.showToast(消息提示框) --> <button bindtap"handleShowToast&…

微信小程序之弹出框

微信小程序中toast消息提示框只有两种显示的效果&#xff0c;就是成功和加载&#xff0c;使用wx.showToast(OBJECT)。 看下有关参数说明&#xff1a; 代码很简单&#xff1a; wx.showToast({title: 成功,icon: succes,duration: 1000,mask:true}) mask属性好像并没有起作用。有…

微信小程序弹窗

微信小程序自定义底部、顶部、中间、左边、右边弹窗 简单的微信小程序弹窗功能&#xff0c;具体实现过程&#xff0c;请浏览代码。 顶部弹出窗图例&#xff1a; 中间弹出窗图例&#xff1a; 底部弹出窗图例&#xff1a; 左边弹出窗图例&#xff1a; 右边弹出窗图例&#x…

微信小程序弹窗提示怎么写

第一种&#xff1a;弹出提示框&#xff0c;可以选择确定或者取消。 代码&#xff1a; wx.showModal({ title: 提示, content: 这是一个模态弹窗, success: function (res) { if (res.confirm) {//这里是点击了确定以后 console.log(用户点击…

微信小程序的弹窗提示

第一种&#xff1a;弹出提示框&#xff0c;用户可以选择确定或者取消&#xff0c;且都带有回调。 wx.showModal({title: 提示,content: 这是一个模态弹窗,success: function (res) {if (res.confirm) { //这里是点击了确定以后console.log(用户点击确定)} else { //这里是点击了…

CSS中水平居中、垂直居中和水平同时垂直居中

1.水平居中 2.垂直居中 3.水平并垂直居中 flex布局用到父元素上&#xff0c;绝对定位用到子元素上。

HTML/CSS:图片居中(水平居中和垂直居中)

css图片居中分css图片水平居中和垂直居中两种情况&#xff0c;有时候还需要图片同时水平垂直居中。 css图片水平居中 1.利用margin: 0 auto实现图片水平居中 利用margin: 0 auto实现图片居中就是在图片上加上css样式margin: 0 auto 如下&#xff1a; <div style"text-…

前端|如何让一个元素水平居中/垂直居中?

不知道你们是否有这样的体验&#xff0c;水平居中在前端中经常使用&#xff0c;但是&#xff01;&#xff01;&#xff01;每次一用就各种不起作用。各种justify-content,align-item,text-align,margin&#xff0c;经过种种尝试之后&#xff0c;终于能够居中了&#xff0c;但下…

微信小程序元素水平居中或垂直居中

.wxml<view class"father"> <view class"children1">子元素1</view> <view class"children2">子元素2</view> <view class"children3">子元素3</view> </view>.wxss.father{display:…

【CSS】元素居中总结-水平居中、垂直居中、水平垂直居中

【CSS】元素居中 一、 水平居中1.行内元素水平居中&#xff08;1&#xff09;text-align 2.块级元素水平居中2.1 margin&#xff08;1&#xff09;margin 2.2布局&#xff08;1&#xff09;flex justify-content&#xff08;推荐&#xff09;&#xff08;2&#xff09; flexmar…

关于照片(img)的水平居中和垂直居中

本文主要是讲述照片&#xff08;img&#xff09;的水平居中和垂直居中&#xff0c;但是其他元素的水平居中和垂直居中也可借鉴此文。 水平居中&#xff1a; 1.将img元素设置成块级元素 img {display: block;margin: 0 auto;} 2.flex布局 .box1 {width: 100px;height: 100p…