我是靠谱客的博主 笑点低嚓茶,这篇文章主要介绍Vant UI + Vue + Cli3.0 + Rem移动端项目搭建,现在分享给大家,希望可以做个参考。

Vant UI + Vue + Cli3.0 + Rem移动端项目搭建

1. 创建vue项目

  • 创建项目
复制代码
1
2
vue create vant-demo
  • 引入less (通过vue ui 可视化页面安装依赖插件)
复制代码
1
2
vue ui

2. 引入vant ui

复制代码
1
2
npm i vant -S

3. 按需引入

3-1. 安装babel 插件
复制代码
1
2
npm i babel-plugin-import -D

温馨提示:在使用自动按需引入的时候,在使用相关组件的时候,需要在maim.js中一一引入,如下:

复制代码
1
2
3
4
5
6
import { Button,Cell, CellGroup } from 'vant'; Vue.use(Cell); Vue.use(CellGroup) Vue.use(Button);
3-2. 配置babel.config.js
复制代码
1
2
3
4
5
6
7
8
9
10
module.exports = { plugins: [ ['import', { libraryName: 'vant', libraryDirectory: 'es', style: true }, 'vant'] ] };

4. Rem适配

4-1. 安装postcss-pxtoremamfe-flexible
复制代码
1
2
3
npm install postcss-pxtorem --save-dev npm i -S amfe-flexible
4-2. 配置vue.config.js
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module.exports = { lintOnSave: true, css: { loaderOptions: { postcss: { plugins: [ require('postcss-pxtorem')({ rootValue : 37.5, // 换算的基数 propList : ['*'], }), require('autoprefixer')({ browsers: ['Android >= 4.0', 'iOS >= 8'] }) ] } } }, }
4-3. 配置main.js
复制代码
1
2
import 'amfe-flexible/index.js'

5. 配置完成

最后

以上就是笑点低嚓茶最近收集整理的关于Vant UI + Vue + Cli3.0 + Rem移动端项目搭建的全部内容,更多相关Vant内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部