uni-app項(xiàng)目中引入Vant?UI組件庫完美避坑指南(純凈版)
第一步,HBuilder X中新建一個(gè)uni-app的項(xiàng)目
1、添加項(xiàng)目名稱,選擇文件路徑
2、選擇默認(rèn)模板
3、Vue版本選擇(若無其他需求,點(diǎn)擊創(chuàng)建即可)

第二步,HBuilder X提示項(xiàng)目創(chuàng)建成功,在HBuilder X用命令行窗口打開創(chuàng)建的項(xiàng)目(或直接在創(chuàng)建的項(xiàng)目文件夾內(nèi)用cmd指令打開)



第三步,輸入npm init -y 指令,創(chuàng)建項(xiàng)目配置文件(即package.json);


第四步,輸入npm i @vant/weapp -S --production下載vant


安裝完成后,項(xiàng)目中會(huì)多出一個(gè)依賴項(xiàng),也代表安裝成功

第五步,在項(xiàng)目的根路徑下,創(chuàng)建wxcomponents目錄,并將依賴項(xiàng)(node_modules)中@vant文件夾下的dist復(fù)制到wxcomponents,并修改文件夾名為vant;

第六步,在pages.json中注冊(cè)并引入組件

以下為組件的全局注冊(cè),可根據(jù)需求按需導(dǎo)入組件:
"usingComponents": {
"van-action-sheet": "/wxcomponents/vant/action-sheet/index",
"van-area": "/wxcomponents/vant/area/index",
"van-button": "/wxcomponents/vant/button/index",
"van-card": "/wxcomponents/vant/card/index",
"van-cell": "/wxcomponents/vant/cell/index",
"van-cell-group": "/wxcomponents/vant/cell-group/index",
"van-checkbox": "/wxcomponents/vant/checkbox/index",
"van-checkbox-group": "/wxcomponents/vant/checkbox-group/index",
"van-col": "/wxcomponents/vant/col/index",
"van-dialog": "/wxcomponents/vant/dialog/index",
"van-field": "/wxcomponents/vant/field/index",
"van-goods-action": "/wxcomponents/vant/goods-action/index",
"van-goods-action-icon": "/wxcomponents/vant/goods-action-icon/index",
"van-goods-action-button": "/wxcomponents/vant/goods-action-button/index",
"van-icon": "/wxcomponents/vant/icon/index",
"van-loading": "/wxcomponents/vant/loading/index",
"van-nav-bar": "/wxcomponents/vant/nav-bar/index",
"van-notice-bar": "/wxcomponents/vant/notice-bar/index",
"van-notify": "/wxcomponents/vant/notify/index",
"van-panel": "/wxcomponents/vant/panel/index",
"van-popup": "/wxcomponents/vant/popup/index",
"van-progress": "/wxcomponents/vant/progress/index",
"van-radio": "/wxcomponents/vant/radio/index",
"van-radio-group": "/wxcomponents/vant/radio-group/index",
"van-row": "/wxcomponents/vant/row/index",
"van-search": "/wxcomponents/vant/search/index",
"van-slider": "/wxcomponents/vant/slider/index",
"van-stepper": "/wxcomponents/vant/stepper/index",
"van-steps": "/wxcomponents/vant/steps/index",
"van-submit-bar": "/wxcomponents/vant/submit-bar/index",
"van-swipe-cell": "/wxcomponents/vant/swipe-cell/index",
"van-switch": "/wxcomponents/vant/switch/index",
"van-tab": "/wxcomponents/vant/tab/index",
"van-tabs": "/wxcomponents/vant/tabs/index",
"van-tabbar": "/wxcomponents/vant/tabbar/index",
"van-tabbar-item": "/wxcomponents/vant/tabbar-item/index",
"van-tag": "/wxcomponents/vant/tag/index",
"van-toast": "/wxcomponents/vant/toast/index",
"van-transition": "/wxcomponents/vant/transition/index",
"van-tree-select": "/wxcomponents/vant/tree-select/index",
"van-datetime-picker": "/wxcomponents/vant/datetime-picker/index",
"van-rate": "/wxcomponents/vant/rate/index",
"van-collapse": "/wxcomponents/vant/collapse/index",
"van-collapse-item": "/wxcomponents/vant/collapse-item/index",
"van-picker": "/wxcomponents/vant/picker/index"
}
如此,即完成了Vant組件庫的引入!

總結(jié)
到此這篇關(guān)于uni-app項(xiàng)目中引入Vant UI組件庫的文章就介紹到這了,更多相關(guān)uni-app引入Vant UI組件庫內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue利用Moment插件格式化時(shí)間的實(shí)例代碼
Moment.js 是一個(gè) JavaScript 日期處理類庫,用于解析、檢驗(yàn)、操作、以及顯示日期。這篇文章主要給大家介紹了關(guān)于vue利用Moment插件格式化時(shí)間的相關(guān)資料,需要的朋友可以參考下2021-05-05
vue-router vuex-oidc動(dòng)態(tài)路由實(shí)例及功能詳解
這篇文章主要為大家介紹了vue-router vuex-oidc動(dòng)態(tài)路由實(shí)例及功能詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11
vue+egg+jwt實(shí)現(xiàn)登錄驗(yàn)證的示例代碼
這篇文章主要介紹了vue+egg+jwt實(shí)現(xiàn)登錄驗(yàn)證的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
vue中?根據(jù)判斷條件添加一個(gè)或多個(gè)style及class的寫法小結(jié)
這篇文章主要介紹了vue中?根據(jù)判斷條件添加一個(gè)或多個(gè)style及class的寫法,文中給大家補(bǔ)充介紹了關(guān)于vue里:class的使用結(jié)合自己的實(shí)現(xiàn)給大家講解,需要的朋友可以參考下2023-03-03
vue+iview/elementUi實(shí)現(xiàn)城市多選
這篇文章主要介紹了vue+iview/elementUi實(shí)現(xiàn)城市多選,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
詳解Vue項(xiàng)目編譯后部署在非網(wǎng)站根目錄的解決方案
這篇文章主要介紹了Vue項(xiàng)目編譯后部署在非網(wǎng)站根目錄的解決方案,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04
Vue+element 日期時(shí)間組件選擇器精確到分鐘禁止選秒的配置方法
文章介紹如何在Vue+Element UI中配置日期時(shí)間選擇器精確到分鐘并禁用秒選擇,通過設(shè)置顯示格式和樣式實(shí)現(xiàn),同時(shí)提供相關(guān)擴(kuò)展內(nèi)容參考,感興趣的朋友一起看看吧2025-07-07
vue前端獲取django后端數(shù)據(jù)實(shí)現(xiàn)方式
這篇文章主要介紹了如何在Vue組件中使用axios獲取和處理數(shù)據(jù),并在模板中展示這些數(shù)據(jù),文章還詳細(xì)講解了Vue的生命周期、v-for指令的使用以及axios與ajax的區(qū)別2026-02-02

