微信小程序用vant,dialog弹出框

官网如下:
https://youzan.github.io/vant-weapp/#/dialog

看效果

1、json中引入

"usingComponents": {
    "van-dialog": "/miniprogram_npm/@vant/weapp/dialog/index"
  }

2、js引入

import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';

3、wxml引入

<van-dialog id="van-dialog" />


<van-dialog id="wan-not-pass"
  use-slot
  title="请填写原因"
  show="{{ showDialog }}"
  show-cancel-button
  show-confirm-button
  confirm-button-text="确定"
  bind:close="onClose"
>

4、默认调用

handleDelayPass() {
    console.log('通过');
    let _this = this;
    let {id} = _this.data;
    
    Dialog.confirm({
      title: '提示',
      message: '确认通过延迟申请审核吗?',
    })
      .then(() => {
        // on confirm
        httpRequest('/StreetManagerAssign/checkDelayApply', {
          id: id
        }, ({
          data
        }) => {
          // 页面刷新
          wx.showToast({
            icon: 'success',
            title: '操作成功',
            duration: 2000,
            success: function(){
              setTimeout(function(){
                // 页面刷新
                _this.onShow()
              }, 2000)
            }
          })
        }, err => {}, '')
      })
      .catch(() => {
        // on cancel
      });
    
  }

5、自定义调用

handleDelayNotPass() {
    console.log('不通过');
    this.setData({
      showDialog:true,
      delay_check_result:""
    });

  },
  onClose(e) {
    console.log(e);
    let _this = this;
    if (e.detail == 'confirm') {
      console.log('确认不通过');
      let {id,delay_check_result} = _this.data;
      if (!delay_check_result) {
        wx.showToast({
          title: '请填写原因',
          icon: 'none',
        })
      } else {
        httpRequest('/StreetManagerAssign/checkDelayApply', {
          id: id,
          type: 2,
          delay_check_result:delay_check_result
        }, ({
          data
        }) => {
          // 页面刷新
          wx.showToast({
            icon: 'success',
            title: '操作成功',
            duration: 2000,
            success: function(){
              setTimeout(function(){
                // 页面刷新
                _this.onShow()
              }, 2000)
            }
          })
        }, err => {}, '')
      }
    }
    
  },
  // 改变审核不通过原因
  onChangeContent(e){
    this.setData({  delay_check_result:e.detail.value})
  }

小结:基本满足各种需求,可以灵活运用组件模式来自用处理弹出层的业务。

posted @   TBHacker  阅读(3052)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2018-12-22 Tp5,Service使用
2018-12-22 CSS再学习 之背景色 背景图片
2018-12-22 Ubuntu终端常用的快捷键,光标移动到开始位置
2018-12-22 CSS 再学习,基础篇
2016-12-22 Java存储过程调用CallableStatement
2016-12-22 Javascript链式调用案例
2015-12-22 mysql常用查询归纳
点击右上角即可分享
微信分享提示