30分钟~使用uni-app框架-整合vant、nuxt

uni-app搭建项目

1. 通过 HBuilderX 可视化界面

30分钟~使用uni-app框架-整合vant、nuxt_第1张图片

2. 通过vue-cli命令行

vue create -p dcloudio/uni-preset-vue my-project

uni-app整合vant

前言

vant ui有h5版和微信小程序版。其h5版 (vant)只能用于h5,其微信小程序版(vant weapp)可用于微信和App,从uni-app 2.4.7起,H5和QQ小程序也支持了微信小程序组件。

H5版本

通过 npm & yarn 安装 -&link

# 通过 yarn 安装 注意指定版本
yarn add vant

# 通过 npm 安装 2.10.6
# Vue 2 项目,安装 Vant 2
npm i vant@latest-v2

引入 vant 组件(全局引入)
注意:1、是否全局引入,根据项目而定

2、现使用node版本12.6.0,如果使用16.15.0会出现版本兼容问题(引入 vant/lib/index.css 报错)

// 引入vant
// #ifdef H5
import Vant from 'vant';
import {
	ConfigProvider
} from "vant";
import 'vant/lib/index.css';
// #endif



// #ifdef H5
app.use(Vant); //
app.use(ConfigProvider);
// #endif

微信小程序版本

使用步骤

下载代码

  • 在项目根目录下新建 wxcomponents 目录 ,此目录应该与 components 目录同级。

  • 直接通过 git 下载 vant-weapp 最新源代码,并将dist目录拷贝到新建的wxcomponents目录下,并重命名distvant-weapp

  • 在 pages.json 的 globalStyle 中 引入所需要的组件

  • "globalStyle": {
    		"pageOrientation": "portrait",
    		"navigationBarTitleText": "Hello uniapp",
    		"navigationBarTextStyle": "white",
    		"navigationBarBackgroundColor": "#007AFF",
    		"backgroundColor": "#F8F8F8",
    		"backgroundColorTop": "#F4F5F6",
    		"backgroundColorBottom": "#F4F5F6",
    		"usingComponents": { //这里为方便,全局引入了所有组件,也可以在某个page下单独引用某个组件
    			"demo-block": "/wxcomponents/vant/demo-block/index",
    			"van-action-sheet": "/wxcomponents/vant/action-sheet/index",
    			"van-area": "/wxcomponents/vant/area/index",
    			// "van-badge": "/wxcomponents/vant/badge/index",
    			// "van-badge-group": "/wxcomponents/vant/badge-group/index",
    			"van-button": "/wxcomponents/vant/button/index",
    			"van-card": "/wxcomponents/vant/card/index",
    			"van-cell": "/wxcomponents/vant/cell/index",
    			"van-cell-group": "/wxcomponents/vant/cell-group/index",
    			"van-checkbox": "/wxcomponents/vant/checkbox/index",
    			"van-checkbox-group": "/wxcomponents/vant/checkbox-group/index",
    			"van-col": "/wxcomponents/vant/col/index",
    			"van-dialog": "/wxcomponents/vant/dialog/index",
    			"van-field": "/wxcomponents/vant/field/index",
    			"van-goods-action": "/wxcomponents/vant/goods-action/index",
    			"van-goods-action-icon": "/wxcomponents/vant/goods-action-icon/index",
    			"van-goods-action-button": "/wxcomponents/vant/goods-action-button/index",
    			"van-icon": "/wxcomponents/vant/icon/index",
    			"van-loading": "/wxcomponents/vant/loading/index",
    			"van-nav-bar": "/wxcomponents/vant/nav-bar/index",
    			"van-notice-bar": "/wxcomponents/vant/notice-bar/index",
    			"van-notify": "/wxcomponents/vant/notify/index",
    			"van-panel": "/wxcomponents/vant/panel/index",
    			"van-popup": "/wxcomponents/vant/popup/index",
    			"van-progress": "/wxcomponents/vant/

你可能感兴趣的:(微信小程序,小程序)