第一章 Vant的引入和基本使用

Vant UI组件库基本使用

一、Vant官网

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

二、安装Vant

npm install --save vant

三、安装插件 babel-plugin-import

npm i babel-plugin-import -D

.babelrc中更改添加

{
  "presets": ["es2015", "stage-3"],
  "plugins": ["transform-runtime",
    ["import", {
      "libraryName": 'vant',

      "style": true
    }, 'vant']
    ],
  "comments": false
}  

模板 

<template>
    <div class="navbar">
        # 组件使用
        <van-nav-bar
          :title="title"
        />
    </div>
</template>

<script>
    # 导入需要使用的组件
    import { NavBar } from 'vant';
    
    export default{
        name: 'navBar',
        components:{    # 组件声明
            [NavBar.name]:NavBar
        },
        data() {
            return {
                title: '全视眼镜商城'
            }
        },
    }
</script>

<style>
# 样式定制
.van-nav-bar{
    background: red;
}
.van-nav-bar__title{
    color: white;
}
</style>  

 

atzhang: 说明: 引入方式为

import { NavBar } from 'vant';  [元件.name]:元件

        components: {
            [NavBar.name]: NavBar,
            [Cell.name]: Cell,
            [CellGroup.name]: CellGroup,
            [Button.name]:Button,
            [Field.name]:Field,
            [Form.name]:Form,
            [Notify.name]:Notify,
            [Collapse.name]:Collapse,
            [CollapseItem.name]:CollapseItem,
            [List.name]:List,
            [Col.name]:Col,
            [Row.name]:Row,
            [Empty.name]:Empty,
        },

参考文档:http://bluezyz.com/index.php/archives/214/

  

原文地址:https://www.cnblogs.com/zytcomeon/p/13370396.html