[保姆级教程]在uniapp中使用vant框架

文章目录


导文

uni-app 中使用 Vant 框架,需要遵循几个步骤来确保 Vant 能够正确地在项目中运行。Vant 是一个基于 Vue 的移动端 UI 组件库,它专门为移动端设备设计。虽然 uni-app 支持多平台,但使用 Vant 时,主要关注它在移动端的表现。

以下是在 uni-app 中使用 Vant 的步骤:

安装 Vant

在你的 uni-app 项目根目录下,使用 npm 或 yarn 来安装 Vant

使用 npm:

bash 复制代码
npm install vant --save
//或者
npm i @vant/weapp -S --production

或使用 yarn:

bash 复制代码
yarn add vant

在uniapp项目中的pages.json中配置easycom,实现组件的自动按需引入:

bash 复制代码
{
  "easycom": {
    "autoscan": true,
    "custom": {
      "^van-(.*)": "@vant/weapp/dist/$1/index"
    }
  }
}

在页面中使用Vant Weapp组件,例如使用按钮组件(Button):

bash 复制代码
<template>
  <view>
    <van-button type="primary">按钮</van-button>
  </view>
</template>

确保你的uniapp项目支持npm以及小程序的分包加载机制。如果遇到问题,检查是否按照Vant Weapp的文档进行了相应的配置。

其他

安装报错

dart 复制代码
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: myuniappsa@0.1.0
npm ERR! Found: vue@2.6.14
npm ERR! node_modules/vue
npm ERR!   vue@">= 2.6.14 < 2.7" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^3.0.0" from vant@4.9.1
npm ERR! node_modules/vant
npm ERR!   vant@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\Administrator\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2024-06-21T03_57_27_712Z-debug-0.log

原因:版本导致的

解决方法:切换npm版本 或者 uniapp版本 或者vant版本

官网地址

http://mui.ucmed.cn/#/zh-CN/quickstart

您好,我是肥晨。

欢迎关注我获取前端学习资源,日常分享技术变革,生存法则;行业内幕,洞察先机。

相关推荐
iOS阿玮14 小时前
碰到一个不听劝的老板,喜提4.3a!
uni-app·app·apple
聊询QQ:276998851 天前
基于Matlab的转速开环恒压频比异步电动机调速系统设计报告与仿真程序
uni-app
2501_915106321 天前
iOS 抓不到包怎么办?从 HTTPS 代理排查到 TCP 数据流捕获的全链路解决方案
android·tcp/ip·ios·小程序·https·uni-app·iphone
游戏开发爱好者81 天前
APP上架苹果应用商店经验教训与注意事项
android·ios·小程序·https·uni-app·iphone·webview
济南壹软网络科技有限公司1 天前
沉浸式体验革命:壹软科技2025新版盲盒源码前端3D渲染与个性化运营技术解析
前端·科技·uni-app·开源·php·盲盒源码
Qin_jiangshan1 天前
flutter和reactNative以及uniapp区别
flutter·react native·uni-app
MrTan1 天前
Uni-App 鸿蒙应用微信相关功能上架踩坑:自制微信安装检测插件
uni-app·harmonyos
2501_916007471 天前
苹果应用商店上架的系统逻辑,从产品开发到使用 开心上架 上架IPA 交付审核流程
android·ios·小程序·https·uni-app·iphone·webview
IT 前端 张1 天前
Uni-app 实现全局无操作监听:自动退出弹窗倒计时功能
运维·服务器·uni-app
一只月月鸟呀1 天前
使用node和@abandonware/bleno写一个ble模拟设备,用Uni-app模拟终端连接
uni-app