1. vant 官网

https://youzan.github.io/vant/#/zh-CN/quickstart

2. 通 npm 安装

npm i vant -S

3.安装 babel-plugin-import 插件

babel-plugin-import 是一款 babel 插件,它会在编译过程中将 import 的写法自动转换为按需引入的方式npm i babel-plugin-import -D

4.在 babel.config.js 中配置

plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]

5.接着你可以在代码中直接引入 Vant 组件

<template>
<div class="con">
<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>
</div>
</template> <script>
import { Button } from 'vant';
export default {
name:"Myindex",
components: {
[Button.name]: Button
},
data() {
return { }
}
}
</script> <style scoped>
.con{
text-align: center;
}
button{
display: block;
margin: 0 auto;
}
</style>

或者不在单个页面引用,在main.js全局引入

import Vue from 'vue'
import 'lib-flexible'
import App from './App.vue' import {
Cell,
CellGroup,
Icon,
NavBar,
Search,
List,
Toast,
Button,
Tab, Tabs,
Col,
Row,
Calendar,
Dialog,
DropdownMenu, DropdownItem
} from 'vant'; Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Icon);
Vue.use(NavBar);
Vue.use(Search);
Vue.use(List);
Vue.use(Toast);
Vue.use(Button);
Vue.use(Tab);
Vue.use(Tabs);
Vue.use(Col);
Vue.use(Row);
Vue.use(Calendar);
Vue.use(Dialog);
Vue.use(DropdownMenu);
Vue.use(DropdownItem); Vue.config.productionTip = false new Vue({
render: h => h(App),
}).$mount('#app')

6.rem 适配

Vant 中的样式默认使用px作为单位,
   postcss-pxtorem 是一款 postcss 插件,用于将单位转化为 rem。
   lib-flexible  用于设置rem基准值

(1) 安装postcss-pxtorem

npm install postcss-pxtorem --save-dev

(2)安装lib-flexible

npm install --save lib-flexible


(3)在main.js中引入lib-flexible

import  'lib-flexible';

(4)在postcss.config.js文件中进行配置

实际上,我完全找不到这个文件,新建一个(很香)

module.exports = {
plugins: {
autoprefixer: {
overrideBrowserslist: ['Android >= 4.0', 'iOS >= 7']
},
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*']
}
}
}

7.底部安全区适配

iPhone X 等机型底部存在底部指示条,指示条的操作区域与页面底部存在重合,容易导致用户误操作,因此我们需要针对这些机型进行底部安全区适配。Vant 中部分组件提供了safe-area-inset-bottom属性,设置该属性后,即可在对应的机型上开启适配,如下示例:

<!-- 在 head 标签中添加 meta 标签,并设置 viewport-fit=cover 值 -->
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
/> ................................................ <!-- 开启 safe-area-inset-bottom 属性 -->
<van-number-keyboard safe-area-inset-bottom /> <!--例 -->
<template>
<van-tabbar :safe-area-inset-bottom="true">
<van-tabbar-item icon="home-o">首页</van-tabbar-item>
<van-tabbar-item icon="orders-o">文章</van-tabbar-item>
</van-tabbar>
</template>

vant引入及配置的更多相关文章

  1. 电商网站开发记录(三) Spring的引入,以及配置详解

    1.web.xml配置注解<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi=& ...

  2. maven-腾讯SDK(QQ)接口java引入pom配置

    maven的pom.xml配置 <dependency> <groupId>net.gplatform</groupId> <artifactId>Sd ...

  3. spring.xml从外部文件引入数据库配置信息

    <!-- 分散配置 --> <context:property-placeholder location="classpath:jdbc.properties" ...

  4. Spring中如何使用自定义注解搭配@Import引入内外部配置并完成某一功能的启用

    文章背景 有一个封装 RocketMq 的 client 的需求,用来提供给各项目收.发消息,但是项目当中常常只使用收或者发消息的单一功能,而且不同的项目 group 等并不相同而且不会变化,可以在项 ...

  5. 项目引入非配置的文件,打成war包后测试报错的可能原因

    写在前边 这阵子有点忙,开发一个微服务项目中读取配置文件的时候在本地测试是可以的,但是一到测试环境就报错,经查看发现是因为发布的时候是用的war包,使用java -jar xxx.war启动的,所以用 ...

  6. Vue项目使用vant框架

    近期在开发h5端项目,用到vant框架,vant是一款基于Vue的移动UI组件,看了vant的官方文档(https://youzan.github.io/vant/#/zh-CN/)感觉不错,功能比较 ...

  7. vue3.0+vite+ts项目搭建--vite.config.ts配置(三)

    vite.config.ts配置 配置路径处理模块 安装ts的类型声明文件 yarn add @types/node -D 通过配置alias来定义路径的别名 resolve: { alias: { ...

  8. webpack构建vue项目(配置篇)

    最近公司要求用vue重构项目,还涉及到模块化开发,于是乎,我专门花了几天的时间研究了一下webpack这个目前来看比较热门的模块加载兼打包工具,发现上手并不是很容易,现将总结的一些有关配置的心得分享出 ...

  9. webpack + vuejs 基本配置(一)

    开始之前 本文包含以下技术,文中尽量给与详细的描述,并且附上参考链接,读者可以深入学习: 1.webpack2.Vue.js3.npm4.nodejs —- 这个就不给连接了,因为上面的连接都是在你实 ...

随机推荐

  1. 开发中的PR和MR

    GitLab的是Pull Request缩写.GitHub则是Merge Request也就是MR. 当项目下载后进行更改并提交,每次过程算一次PR,一般会加入管理员审核,通过才能合并到master主 ...

  2. bjdctf_2020_babyrop2(没有成功拿到shell)

    看到程序先例行检查一下 可以看到开启了canary和nx保护,需要注意的是这个acnary 将程序放入ida中shift+f12 没有关键性函数.我们进入main函数中 在main的gift程序里面我 ...

  3. CF999A Mishka and Contest 题解

    Content 能力值为 \(k\) 的小 M 参加一次考试,考试一共有 \(n\) 道题目,每道题目的难度为 \(a_i\).小 M 会选择两头中的一道难度不超过他的能力值题目去做,每做完一道,这道 ...

  4. CF1443A Kids Seating 题解

    Content 有 \(t\) 组询问,每组询问给定一个数 \(n\),试构造出一个长度为 \(n\) 的数列 \(\{a_i\}_{i=1}^n\),使得: \(\forall i\in[1,n], ...

  5. MIUI12.5扫码之后无法连接MIUI+,显示连接失败

    设置-应用设置-应用管理-小米互联通信服务(如果没有找到,进行搜索即可)-清除数据 重新扫码连接就可以连上了 (感觉不怎么样,不知道是不是我网卡,用起来卡卡的...)

  6. 分享一下java需要的一些技术

    1.前言 you are 大哥,老衲很佩服你们_.还是一样的,有我联系方式的人,哪些半吊子不知道要学习哪些技术,一天让我整知识点,老衲也有事情做的,哪有那么多时间来一直搞知识点啊,我的博客更新很慢的, ...

  7. IDEA安装vue.js插件后,new没有Vue component

    首先要安装vue相关的插件vue.js 但是很多人安装vue.js右键发现没有vue Componment,解决方法如下 Settings>Editor>File and Code Tem ...

  8. nim_duilib(3)之按钮

    introduction 更多控件用法,请参考 here 和 源码. 本文的代码基于这里 lets go xml文件添加代码 下面的xml文件内容,删除label控件的相关代码,增加了3个按钮. 其中 ...

  9. 1119 - Pimp My Ride

    1119 - Pimp My Ride    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB To ...

  10. 快速恢复update了的orcale数据表

    在update的时候 没有写条件 将整个表中的数据全部都更新了,这时候怎么办呢? orcale提供了以下的方法产看某一个时间戳, 所执行的sql的语句内容, 同时可以利用该这个时间戳查看当时语句执行显 ...