如何编写微信小程序封装自定义弹窗的代码实现?

更新于
2026-10-02 09:13:23
0阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计1699个文字,预计阅读时间需要7分钟。

最近在开发小程序的登录功能,需要同时获取用户手机号和头像等个人信息。但小程序不支持单个接口同时获取两种数据,因此想自定义一个弹窗,通过弹窗按钮触发获取手机号事件。

最近在做小程序的登录,需要同时获取用户手机号和头像昵称等信息,但是小程序又不支持单个接口同时获取两种数据,因此想到自定义一个弹窗,通过弹窗按钮触发获取手机号事件。记录一下。

具体代码如下:

业务代码中:

  在业务代码中引入dialog组件即可

<dialog visible="{{dialogVisible}}" showFooter="{{footerVisible}}" title="测试一下">     <view class='dialog-body' slot="dialog-body">       <view class='dialog-content'>申请获取你微信绑定的手机号</view>       <view class='dialog-footer' slot="dialog-footer">         <button class='cancel-btn' bindtap="close">取消</button>         <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" class='confirm-btn'>授权</button>       </view>     </view>   </dialog>

dialog组件:

component下面新建dialog。

阅读全文
标签:实现代码

本文共计1699个文字,预计阅读时间需要7分钟。

最近在开发小程序的登录功能,需要同时获取用户手机号和头像等个人信息。但小程序不支持单个接口同时获取两种数据,因此想自定义一个弹窗,通过弹窗按钮触发获取手机号事件。

最近在做小程序的登录,需要同时获取用户手机号和头像昵称等信息,但是小程序又不支持单个接口同时获取两种数据,因此想到自定义一个弹窗,通过弹窗按钮触发获取手机号事件。记录一下。

具体代码如下:

业务代码中:

  在业务代码中引入dialog组件即可

<dialog visible="{{dialogVisible}}" showFooter="{{footerVisible}}" title="测试一下">     <view class='dialog-body' slot="dialog-body">       <view class='dialog-content'>申请获取你微信绑定的手机号</view>       <view class='dialog-footer' slot="dialog-footer">         <button class='cancel-btn' bindtap="close">取消</button>         <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" class='confirm-btn'>授权</button>       </view>     </view>   </dialog>

dialog组件:

component下面新建dialog。

阅读全文
标签:实现代码