前言
vant ui有h5版和微信小程序版。其h5版只能用於h5,其微信小程序版(vant weapp)可用於微信和App,從uni-app 2.4.7起,H5和QQ小程序也支持了微信小程序組件。
使用步驟
下載代碼
-
在項目根目錄下新建
wxcomponents
目錄 ,此目錄應該與components
目錄同級。 -
直接通過
git
下載vant-weapp
最新源代碼,並將dist
目錄拷貝到新建的wxcomponents
目錄下,並重命名dist
為vant-weapp
。 -
在pages.json的globalStyle中 引入所需要的組件
試試是否成功

<template>
<div>
<van-picker
v-if="flag"
:columns="columns"
@change="changePicker"
/>
<van-button @click="show">顯示</van-button>
</div>
</template>
<script>
export default {
data() {
return {
columns: ["杭州", "寧波", "溫州", "嘉興", "湖州"],
flag: false
};
},
methods: {
show() {
console.log("1 =", "show");
this.flag = !this.flag;
},
changePicker(event) {
console.log("1 =", event);
}
}
};
</script>
注意事項
Vant組件中Notify
消息提示比較特殊
不僅需要在pages.json的globalStyle中 引入還需要再main.js中添加到vue原型上
//main.js
import Notify from './wxcomponents//vant/notify/notify';
Vue.prototype.$notify = Notify
然后在頁面中使用
<template>
<view>
<van-button @click="showNotify">彈出提示</van-button>
<van-notify id="van-notify" />
</view>
</template>
<script>
export default {
methods: {
showNotify() {
this.$notify({ type: "danger", message: "通知內容" });
}
}
};
</script>