Advertisement

uni-app引入vant

阅读量:

安装vant:

复制代码
  
    
 # 通过 npm 安装
    
 npm i @vant/weapp -S --production
    
  
    
 # 通过 yarn 安装
    
 yarn add @vant/weapp --production

安装后出现@vant

复制dist文件夹:

前往新建的wxcomponents:粘贴,并改名vant:

所以vant里面是:

App.vue引入样式:

pages.json: 引入组件

index.vue 使用组件:

复制代码
 <template>

    
 <view>
    
 			<view>Vant Weapp组件</view>
    
 			<van-button block type="default">默认按钮</van-button>
    
 			<van-button block type="primary">主要按钮</van-button>
    
 			<van-button block type="info">信息按钮</van-button>
    
 			<van-button block type="warning">警告按钮</van-button>
    
 			<van-button type="danger">危险按钮</van-button>
    
 		</view>
    
  
    
 	
    
 </template>
    
  
    
 <script>
    
 </script>
    
  
    
 <style>
    
 </style>
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/zMEWhkTvrQBfoReynU7LNPDcOuF6.png)

这个时候特别注意:

如果使用微信小程序开发,main.js为:

复制代码
 import App from './App'

    
  
    
 // #ifndef VUE3
    
 import Vue from 'vue'
    
 import './uni.promisify.adaptor'
    
 Vue.config.productionTip = false
    
 App.mpType = 'app'
    
 const app = new Vue({
    
   ...App
    
 })
    
 app.$mount()
    
 // #endif
    
  
    
 // #ifdef VUE3
    
 import { createSSRApp } from 'vue'
    
  
    
  
    
  
    
  
    
 export function createApp() {
    
   const app = createSSRApp(App)
    
   
    
   return {
    
     app
    
   }
    
 }
    
  
    
 // #endif
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/WafJU2Q0nujeV7bMGTRg5xPFqvE3.png)

如果是PC开发,main.js为:(加入了vant)

复制代码
  
    
 // #ifndef VUE3
    
 import App from './App'
    
 import Vue from 'vue'
    
 import './uni.promisify.adaptor'
    
 import Vant from 'vant'
    
 import 'vant/lib/index.css'
    
  
    
 Vue.use(Vant)
    
  
    
 Vue.config.productionTip = false
    
 App.mpType = 'app'
    
 const app = new Vue({
    
   ...App
    
 })
    
 app.$mount()
    
  
    
 // #endif
    
  
    
 // #ifdef VUE3
    
 import { createSSRApp } from 'vue'
    
 import App from './App'
    
 import Vant from 'vant'
    
 import 'vant/lib/index.css'
    
  
    
 export function createApp() {
    
   const app = createSSRApp(App)
    
   app.use(Vant)
    
   return {
    
     app
    
   }
    
 }
    
  
    
 // #endif
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-18/TzGbjAsWJ6Qw5ZR0pkEXcDYh4gdn.png)

最后展示:

全部评论 (0)

还没有任何评论哟~