uniapp 全局引入vant 组件库

vant4官方文档

vant2官方文档

vant3官方文档

一、创建uniapp项目 + vue3

在这里插入图片描述

二、通过npm安装vant

  • vue3项目,安装最新版Vant npm i vant
  • vue2项目,安卓vant2 npm i vant@latest-v2
  • node_modules中有@vant证明下载好了

在这里插入图片描述

三、main.js引入vant

  • uniapp项目中找到main.js文件
// #ifdef VUE3
import { createSSRApp } from 'vue'
import Vant from 'vant'
import 'vant/lib/index.css'
export function createApp() {
	const app = createSSRApp(App)
	app.use(Vant)
	return {
		app
	}
}
// #endif

四、在根目录下创建一个文件夹wxcomponents

五、在pages.json中配置

在这里插入图片描述
直接粘贴就行

"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#f1f1f1",
		"backgroundColor": "#F8F8F8",
		"usingComponents": {
			"van-dropdown-menu": "/wxcomponents/dist/dropdown-menu/index",
			"van-dropdown-item": "/wxcomponents/dist/dropdown-item/index",
			"van-action-sheet": "/wxcomponents/dist/action-sheet/index",
			"van-area": "/wxcomponents/dist/area/index",
			"van-button": "/wxcomponents/dist/button/index",
			"van-card": "/wxcomponents/dist/card/index",
			"van-cell": "/wxcomponents/dist/cell/index",
			"van-cell-group": "/wxcomponents/dist/cell-group/index",
			"van-checkbox": "/wxcomponents/dist/checkbox/index",
			"van-checkbox-group": "/wxcomponents/dist/checkbox-group/index",
			"van-col": "/wxcomponents/dist/col/index",
			"van-dialog": "/wxcomponents/dist/dialog/index",
			"van-field": "/wxcomponents/dist/field/index",
			"van-goods-action": "/wxcomponents/dist/goods-action/index",
			"van-goods-action-icon": "/wxcomponents/dist/goods-action-icon/index",
			"van-goods-action-button": "/wxcomponents/dist/goods-action-button/index",
			"van-icon": "/wxcomponents/dist/icon/index",
			"van-loading": "/wxcomponents/dist/loading/index",
			"van-nav-bar": "/wxcomponents/dist/nav-bar/index",
			"van-notice-bar": "/wxcomponents/dist/notice-bar/index",
			"van-notify": "/wxcomponents/dist/notify/index",
			"van-panel": "/wxcomponents/dist/panel/index",
			"van-popup": "/wxcomponents/dist/popup/index",
			"van-progress": "/wxcomponents/dist/progress/index",
			"van-radio": "/wxcomponents/dist/radio/index",
			"van-radio-group": "/wxcomponents/dist/radio-group/index",
			"van-row": "/wxcomponents/dist/row/index",
			"van-search": "/wxcomponents/dist/search/index",
			"van-slider": "/wxcomponents/dist/slider/index",
			"van-stepper": "/wxcomponents/dist/stepper/index",
			"van-sticky": "/wxcomponents/dist/sticky/index",
			"van-steps": "/wxcomponents/dist/steps/index",
			"van-submit-bar": "/wxcomponents/dist/submit-bar/index",
			"van-swipe-cell": "/wxcomponents/dist/swipe-cell/index",
			"van-switch": "/wxcomponents/dist/switch/index",
			"van-tab": "/wxcomponents/dist/tab/index",
			"van-tabs": "/wxcomponents/dist/tabs/index",
			"van-tabbar": "/wxcomponents/dist/tabbar/index",
			"van-tabbar-item": "/wxcomponents/dist/tabbar-item/index",
			"van-tag": "/wxcomponents/dist/tag/index",
			"van-toast": "/wxcomponents/dist/toast/index",
			"van-transition": "/wxcomponents/dist/transition/index",
			"van-tree-select": "/wxcomponents/dist/tree-select/index",
			"van-datetime-picker": "/wxcomponents/dist/datetime-picker/index",
			"van-rate": "/wxcomponents/dist/rate/index",
			"van-collapse": "/wxcomponents/dist/collapse/index",
			"van-collapse-item": "/wxcomponents/dist/collapse-item/index",
			"van-picker": "/wxcomponents/dist/picker/index",
			"van-share-sheet": "/wxcomponents/dist/share-sheet/index",
			"van-circle": "/wxcomponents/dist/circle/index",
			"van-grid": "/wxcomponents/dist/grid/index",
			"van-calendar": "/wxcomponents/dist/calendar/index"
		}
	}
  • 在globalStyle中注册所需要的组件,格式如上 路径根据自己
    在这里插入图片描述
  • uniapp中icon图标无法显示,使用图片的方式引入图标即可
  • 感谢参考

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值