一、在Hbulder中创建一个项目,如:uni-vant
二、安装vant:
1.运行命令cmd安装vant到uni-app项目中:
npm i vant@latest-v2 -S
2.安装成功后可以在package.json中看到已经加入该依赖

3.我们可以在根目录中看到下面的文件结构(之后我们使用的将是这个红色框中的目录中),node_modules没有的可以运行命令cmd中安装:npm i

三、进行全局导入vant组件
在main.js中进行挂载Vant组件,主看带有编号的两步
import App from './App'
// 1.导入Vant组件,这里的‘vant’就是我们上面新导入的vant的目录
import Vant from './node_modules/vant/lib/vant';
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// 2. 将Vant组件挂载到Vue上
Vue.use(Vant);
app.$mount()
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif
四、导入vant全局样式,在App.vue中进行导入
复制这段代码到style中:@import '@/node_modules/vant/lib/index.css';

五、在官网中找到想要的组件粘贴复制到你要用的位置。
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<van-button type="primary">主要按钮</van-button>
<van-button type="info">信息按钮</van-button>
<van-button type="default">默认按钮</van-button>
<van-button type="warning">警告按钮</van-button>
<van-button type="danger">危险按钮</van-button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
效果图
