uniapp 引用 vant 組件


uniapp 引用 vant 組件

 

1、下載vant組件

vant的GitHub下載地址下載完成后解壓,然后在項目更目錄下創建文件夾wxcomponents,注意這里的wxcomponents目錄級別和pages在同一級別,然后再該目錄下創建vant目錄。回到剛才解壓的vant目錄,找到dist文件夾,把它復制到vant目錄下

 

 2、引入組件

2.1  首先在app.vue文件內添加

1 @import "/wxcomponents/vant/dist/common/index.wxss";

 

 

 

2.2 在pages.json文件內添加組件引用

 

 你可以選擇在一個頁面的配置文件里面配置,但是只能在這個頁面內使用,你也可以選擇在globalStyle里面配置,是的所有頁面都可以直接使用

1 "usingComponents":{
2     "van-button":"/wxcomponents/vant/dist/button/index",
3     "van-notify":"/wxcomponents/vant/dist/notify/index"
4 }

3、使用組件

3.1   注意notify的使用,她還需要在main.js配置一下,不然就會報$notify is undefined 錯誤。

1 import Notify from './wxcomponents/vant/dist/notify/notify';
2 
3 Vue.prototype.$notify = Notify

 

 3.2 最后,在你要使用的頁面內添加你要使用的組件就可以了。

 1 <template>
 2     <view>
 3         <van-button @click="aa()" type="info">信息按鈕</van-button>
 4         <van-notify id="van-notify" />
 5     </view>
 6 </template>
 7 
 8 <script>
 9     export default {
10         data(){
11             return{
12                 
13             }
14         },
15         methods:{
16             aa(){
17                 this.$notify({ type: "danger", message: "通知內容" });
18             }
19         }
20     }
21 </script>
22 
23 <style>
24 </style>

 

 效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM