vue3 使用vant

使用前提:

vite创建的vue3项目

vanthttps://vant-ui.github.io/vant/#/zh-CN/home

npm i vant

引入样式:

javascript 复制代码
main.js 

import 'vant/lib/index.css'

vant封装

javascript 复制代码
import { showLoadingToast,closeToast,showDialog,showConfirmDialog } from 'vant';


export function dialog(title,msg,success){
  showDialog({
    title: title||'温馨提示',
    message: msg,
  }).then(() => {
    // on close
    if(success){
      return success()
    }
    
  });
}

export  const loading ={
   showLoading:function (msg){
    showLoadingToast({
      message: msg||'加载中...',
      duration: 0, // 持续展示 toast
    })
   },
   hideLoading:function(){
    closeToast();
   }


}

export function confirmDialog(title,msg,success,error){
 return new Promise((resolve, reject) => {
  showConfirmDialog({
    title: title||'温馨提示',
    message:msg,
  })
    .then(() => {
      resolve(true)
      if(success){
        return success()
      }
    })
    .catch(() => {
      resolve(false)
      if(error){
        return error()
      }
    });
 })



}

使用

javascript 复制代码
import { loading } from "@/utils/vant";

loading.showLoading();

//loading.hideLoading()
javascript 复制代码
<script setup>

import { Empty} from "vant"

</script>

<template>
  <div>
   <Empty description="读取用户信息中,请稍后..."></Empty>
  </div>
</template>

我这里只是全局引用了样式,模块没有全局引入模块,需要时再引入

相关推荐
极客密码21 小时前
感谢雷总!Mimo大模型价值¥659/月的 MAX 套餐,让我免费领到了!
前端·ai编程·claude
深念Y1 天前
我明白为什么B站没法在浏览器开直播了——Windows Chrome推流踩坑全记录
前端·chrome·webrtc·浏览器·srs·直播·flv
zhangxingchao1 天前
AI应用开发七:可以替代 RAG 的技术
前端·人工智能·后端
Sun@happy1 天前
现代 Web 前端渗透——基础篇(1)
前端·web安全
希冀1231 天前
【CSS学习第十一篇】
前端·css·学习
隔窗听雨眠1 天前
doctype、charset、meta如何控制整个渲染流水线
java·服务器·前端
kyriewen1 天前
写组件文档写到吐?我用AI自动生成Storybook,同事以后直接抄
前端·javascript·面试
excel1 天前
🧠 Prisma 表名大写 vs SQL 导出小写问题深度解析(附踩坑与解决方案)
前端·后端
周淳APP1 天前
【前端工程化原理通识:从源头到运行时的理论阐述】
前端·编译·打包·前端工程化
五点六六六1 天前
你敢信这是非Native页面写出来的渐变效果吗🌝(底层原理解析
前端·javascript·面试