微信小程序弹窗组件

弹窗组件使用

弹窗组件下载链接

1.组件引入方式,需要引入组件的json中添加组件的相对位置

{
  "usingComponents": {
    "modalView": "相对位置"
  }
}

2.组件基本用法

两个按钮

<modalView show="{{showComponents}}" modalValue="{{modalValue}}" bindCancel="bindCancel" bindConfirm='bindConfirm'></modalView>

一个按钮

<modalView show="{{showComponents}}" modalValue="{{modalValue}}" bindConfirm='bindConfirm'></modalView>

Attributes

参数说明是否必填类型键入值默认值
show控制弹窗显示booleantrue/false———
modalValue弹窗文字内容objectmodalTitle:’’//弹窗标题;modalContent:’’,//弹窗内容;modalBtn:[]//弹窗按钮,最大长度为2———

Events

事件名称说明回调参数
bindCancel取消按钮事件———
bindConfirm确认按钮事件———

两个按钮效果
在这里插入图片描述
一个按钮效果
在这里插入图片描述
wxml部分

<view class='modal-mask' wx:if='{{show}}'>
  <view class='modal-content'>
    <view class="modal-content-title">{{modalValue.modalTitle}}</view>
    <view class="modal-content-text">{{modalValue.modalContent}}</view>
    <view class='modal-footer' wx:if="{{modalValue.modalBtn.length > 1}}">
      <view class='cancel-btn' bindtap='cancel'>{{modalValue.modalBtn[0]}}</view>
      <view class='confirm-btn' bindtap='confirm'>{{modalValue.modalBtn[1]}}</view>
    </view>
    <view class='modal-footer' wx:else>
      <view class='confirm-btn' bindtap='confirm'>{{modalValue.modalBtn[0]}}</view>
    </view>
  </view>
</view>

wxss部分

.modal-mask{
  position: fixed;
  top: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0,0,0,0.5);
  z-index: 999;
  height: 100vh;
  width: 100%;
}
.modal-content{
  width: 80%;
  background-color: #fff;
  border-radius: 10rpx;
  padding: 20rpx;
  text-align: center;
}
.modal-content-title{
  margin: 20rpx;
  font-size: 41rpx;
  color: #333333;
}
.modal-content-text {
  word-wrap: break-word;
}
.modal-footer{
  display: flex;
  flex-direction: row;
  height: 80rpx;
  line-height: 80rpx;
  border-top: 2rpx solid #D2D3D5;
  margin-top: 30rpx;
}
.cancel-btn, .confirm-btn{
  flex: 1;
  height: 100rpx;
  line-height: 100rpx;
  text-align: center;
  font-size: 32rpx;
}
.cancel-btn{
  color: #000;
  border-right: 2rpx solid #D2D3D5;
}
.confirm-btn {
  color: #0C82F1;
}


js部分

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    //是否显示modal弹窗
    show: {
      type: Boolean,
      value: false
    },
    //弹窗描述
    modalValue: {
      type:Object,
      value:{
        modalTitle:'',//弹窗标题
        modalContent:'',//弹窗内容
        modalBtn:[]//弹窗按钮(一个按钮或两个按钮,默认两个)
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
   // 点击取消按钮的回调函数
    cancel() {
      this.setData({ show: false })
      this.triggerEvent('Cancel')  //triggerEvent触发事件
    },
    // 点击确定按钮的回调函数
    confirm() {
      this.setData({ show: false })
      this.triggerEvent('Confirm')
    }
  }
})

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wombat-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值