微信小程序底部弹窗(半屏弹窗)---WeUI组件使用

小程序的底部弹窗(半屏弹窗)

我这里主要是使用小城的原生组件WeUI来完成的,需要引入WeUI组件库。这里就不教如何引入库,主要讲解如何使用Half Screen Dialog标签。
首先就是通过json文件引入到你需要使用组件的页面。

{
  "usingComponents": {
    "mp-half-screen-dialog":"/weui-miniprogram/half-screen-dialog/half-screen-dialog"
  }
}

这里的mp-half-screen-dialog为标签名,可以自己定义标签名,/weui-miniprogram/half-screen-dialog/half-screen-dialog为引入包的相对路径,引入WeUI组件库包的half-screen-dialog的文件。
接下来就是如何使用,首先就是在wxml文件中直接使用标签

<mp-half-screen-dialog></mp-half-screen-dialog>

他的属性主要是以下几个:
extClass:组件类名
title:组件主标题标题
desc:辅助操作描述内容,可以简单的显示一些文字
show:是否开启弹窗(默认为true)主要靠此属性来完成弹出
buttons:辅助操作按钮列表
bindbuttontap:点击辅助操作按钮时触发
bindclose:组件关闭时候触发
以及slot属性。

wxml:

<mp-half-screen-dialog
  etClass="test"
  title="test"
  desc="hello,this is test."
  show="{{show}}"
  buttons="{{buttons}}"
  bindbuttontap="bindButtonTap"
  bindclose="bindClose"
></mp-half-screen-dialog>
<button type="primary"
bindtap="btn">test</button>

js:

data: {
  show:false,
  buttons:[
    {
      type:'default',
      className:'test1',
      text:'测试1',
      value:0
    },{
      type:'primary',
      className:'test2',
      text:'测试2',
      value:1
    }
  ]
},
btn:function(){
  this.setData({show:true})
},
bindClose:function(){
  console.log("bindClose")
},
bindButtonTap:function(e){
  console.log(e.detail)
  this.setData({show:false})
}

大致效果如下图:
在这里插入图片描述
slot属性具体看 小程序开发:小程序的底部弹窗(半屏弹窗)

  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要让用户点击微信小程序弹窗,您需要在弹窗中添加可点击的元素,比如按钮、链接等。具体实现可以参考以下步骤: 1. 在小程序页面中引入弹窗组件(如weuidialog组件)。 2. 在需要弹出弹窗的地方,调用弹窗组件的showModal方法,并设置弹窗的标题、内容、按钮等属性。 3. 在弹窗的内容区域中添加可点击的元素,比如按钮或链接,可以使用微信小程序提供的button组件或者a标签实现。 4. 在点击弹窗中的可点击元素时,可以通过绑定事件的方式触发相应的操作或跳转到其他页面。 以下是一个示例代码: ```html <view> <button bindtap="showModal">点击弹出弹窗</button> </view> <weui-dialog id="weui-dialog" title="提示" show="{{dialogShow}}" bind:cancel="hideModal" bind:confirm="confirm"> <view slot="content"> <view>您确定要执行此操作吗?</view> <button bindtap="confirm">确定</button> <a href="/pages/index/index">去首页</a> </view> </weui-dialog> <script> Page({ data: { dialogShow: false }, showModal: function () { this.setData({ dialogShow: true }); }, hideModal: function () { this.setData({ dialogShow: false }); }, confirm: function () { console.log('用户点击确定'); this.hideModal(); } }) </script> ``` 在这个示例中,我们使用weui-dialog组件作为弹窗,并在弹窗中添加了一个按钮和一个链接,用户可以通过点击这些元素来触发相应的操作或跳转到其他页面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值