小程序之Vant Weapp UI组件库

227 阅读1分钟

安装

第一步:通过npm安装

如果你还没有初始化项目,一定要先初始化项目
1.  npm init 
2.  npm install 

# 3. 通过 npm 安装
npm i @vant/weapp -S --production

# 通过 yarn 安装
yarn add @vant/weapp --production

# 安装 0.x 版本
npm i vant-weapp -S --production

第二步:构建npm包

打开微信开发者工具,点击 工具 -> 构建 npm,并勾选 使用 npm 模块 选项,构建完成后,即可引入组件

第三步:使用

  1. 引入组件
    以 Button 组件为例,只需要在app.json或index.json中配置 Button 对应的路径即可

如果你是通过下载源代码的方式使用 @vant/weapp,请将路径修改为项目中 @vant/weapp 所在的目录。

// app.json
"usingComponents": {
   "van-button": "/miniprogram_npm/@vant/weapp/button/index"
}
  1. 使用组件 引入组件后,可以在 wxml 中直接使用组件
<van-button type="primary">按钮</van-button>