Element-UI快速入门

前言

Element-Ul是一套基于Vue 2.0的桌面端组件库,它是饿了么的开源组件库

安装Element-UI

npm i element-ui -S

引入Element-UI

官方提供了两种的引入方式

完整引入

在main.js中引入
其中样式文件需要单独引入

import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';

Vue.use(ElementUI);

new Vue({
  el: '#app',
  render: h => h(App)
});

按需引入

按需引入需要借助babel-plugin-component ,之后就可以只引入需要的组件,以到达减少项目体积的目的

  1. 安装 babel-plugin-component
npm install babel-plugin-component -D
  1. 然后修改 .babelrc,修改以下
{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}
  1. 引入部分组件
import Vue from 'vue';
import { Button, Select } from 'element-ui';
import App from './App.vue';

Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
/* 或写为
 * Vue.use(Button)
 * Vue.use(Select)
 */

new Vue({
  el: '#app',
  render: h => h(App)
});
  1. 使用导入的组件
<div>
 <el-button>默认按钮</el-button>
 <el-button type="primary">主要按钮</el-button>
 <el-button type="success">成功按钮</el-button>
 <el-button type="info">信息按钮</el-button>
 <el-button type="warning">警告按钮</el-button>
 <el-button type="danger">危险按钮</el-button>
</div>

<template>
  <el-select v-model="value" placeholder="请选择">
    <el-option
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
</template>

<script>
  export default {
    data() {
      return {
        options: [{
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }, {
          value: '选项4',
          label: '龙须面'
        }, {
          value: '选项5',
          label: '北京烤鸭'
        }],
        value: ''
      }
    }
  }
</script>

相关推荐

  1. Element-UI 快速入门

    2024-06-08 06:50:02       13 阅读
  2. Element-UI快速入门

    2024-06-08 06:50:02       16 阅读
  3. Element-UI快速入门

    2024-06-08 06:50:02       15 阅读
  4. Element-ui快速入门

    2024-06-08 06:50:02       13 阅读
  5. Element-UI快速入门

    2024-06-08 06:50:02       11 阅读
  6. Element-UI快速入门

    2024-06-08 06:50:02       10 阅读
  7. Element ui 快速入门

    2024-06-08 06:50:02       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-08 06:50:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-08 06:50:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-08 06:50:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-08 06:50:02       20 阅读

热门阅读

  1. C++中的字符串详解

    2024-06-08 06:50:02       5 阅读
  2. Linux入门学习指南

    2024-06-08 06:50:02       8 阅读
  3. 设计模式之模板方法模式

    2024-06-08 06:50:02       7 阅读
  4. Linux基于V4L2的视频捕捉

    2024-06-08 06:50:02       9 阅读
  5. Unity3D DOTS 10W GPU Intancing 动画与合批优化详解

    2024-06-08 06:50:02       8 阅读
  6. Excel中的SUMPRODUCT函数:使用方法与案例分析

    2024-06-08 06:50:02       9 阅读
  7. 【MyBatisPlus条件构造器】

    2024-06-08 06:50:02       9 阅读
  8. [DT] 翻译笔记

    2024-06-08 06:50:02       6 阅读
  9. uniapp vue 隐藏button的边框

    2024-06-08 06:50:02       9 阅读
  10. 零、测试开发前置知识

    2024-06-08 06:50:02       8 阅读
  11. 【常用工具系列】Git 教程——从入门到大师

    2024-06-08 06:50:02       12 阅读