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

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

由于微信小程序自带的toast及model都有很大的限制,很多产品对弹框的要求是多样化的,于是自己动手封装实现一组弹框功能。该组件只是提供一种实现方式,对样式不满意可自行修改。

实现效果图

  • toast
    toast
  • model
    -model
  • loading
    loading

开发者工具查看效果

如何使用

1、在需要使用的页面引入wxss

@import '../component/wx-layer/wx-layer.wxss';

2、wxml引入模块

<import src='../component/wx-layer/wx-layer.wxml' />
<template is="wxLayer" data="{{...wxLayer}}"/>

3、js引入

import WxLayer from '../component/wx-layer/wx-layer';

Page({
  onLoad() { //onload中初始化组件
    new WxLayer();
  }
})

使用

1、toast: this.showToast(title, duration, mask);

参数类型默认是否必须说明
titlestringyes内容
durationnumber2000no持续时间
maskbooleanfalseno是否使用遮罩层

2、model: this.showModal({title, content, confirmText, cancelText, confirm, showCancel, mask});

参数类型默认是否必须说明
titlestringno标题
contentstringyes提示内容
confirmTextstring确认no确认按钮文案
cancelTextstringno取消按钮文案
confirmfunctionno点击确认回调
showCancelbooleanfalseno是否显示取消按钮
maskbooleanfalseno是否使用遮罩层

3、loading: this.showLoading(mask,text);

参数类型默认是否必须说明
textstringnoloading文案
maskbooleanfalseno是否使用遮罩层

查看元整代码

如果我的代码对你有帮助,请给个start吧! ^^

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值