当前位置:   article > 正文

uniapp 微信小程序 简易封装提示框showToast/showModal/showLoading_uniapp小程序封装 toast

uniapp小程序封装 toast

showModal

// 封装提示框
export const showModal = (content, showCancel = false, title = "提示") => {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title: title,
      content: content,
      showCancel: showCancel,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

showToast

// 封装showToast
export const showToast = (content, icon = "none") => {
  return new Promise((resolve, reject) => {
    uni.showToast({
      title: content,
      icon: icon,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

showLoading

// 封装showLoading
export const showLoading = (content, mask = true) => {
  return new Promise((resolve, reject) => {
    uni.showLoading({
      title: content,
      mask: mask,
      success: (res) => {
        resolve(res);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

页面内使用,引入

import { showModal, showToast, showLoading } from "@/js/common.js";

showModal('1111');
showToast("保存成功");
showLoading("加载中");

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/928188
推荐阅读
相关标签
  

闽ICP备14008679号