在Vue项目中使用Element组件

简介: 记录如何在Vue项目中使用Element-ui组件

0 写在前面

使用组件可以快速进行开发,使用Element UI轻松制作出网页,为前端开发人员大大减轻了代码负担,即使是后端程序员也可以快速上手做出比较精美的界面。
本文记录如何在Vue项目中使用Element。

1 安装

推荐使用npm i element-ui -S命令直接下载。
图文演示:(本文是在WebStream下演示,一下与软件无关,使用任何地方的终端结果都是一样的)
在创建好的Vue目录下直接输入命令npm i element-ui -S
在这里插入图片描述

在这里插入图片描述
出现element -ui@版本号就代表安装成功了。

2 配置

在根目录下的main.js中作以下配置

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

Vue.use(ElementUI);

new Vue({
    store,
    mainPage,
    render: function (h) {
        return h(App)
    }
}).$mount('#app')

重点就是引用并使用

import ElementUI from 'element-ui';
Vue.use(ElementUI);

在这里插入图片描述

3 使用组件

打开Element-网站快速成型工具选择组件
在这里插入图片描述
选择自己需要的组件
在这里插入图片描述
这里以按钮为例
在这里插入图片描述
它们所对应的代码为:

<el-row>
  <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>
</el-row>

<el-row>
  <el-button plain>朴素按钮</el-button>
  <el-button type="primary" plain>主要按钮</el-button>
  <el-button type="success" plain>成功按钮</el-button>
  <el-button type="info" plain>信息按钮</el-button>
  <el-button type="warning" plain>警告按钮</el-button>
  <el-button type="danger" plain>危险按钮</el-button>
</el-row>

<el-row>
  <el-button round>圆角按钮</el-button>
  <el-button type="primary" round>主要按钮</el-button>
  <el-button type="success" round>成功按钮</el-button>
  <el-button type="info" round>信息按钮</el-button>
  <el-button type="warning" round>警告按钮</el-button>
  <el-button type="danger" round>危险按钮</el-button>
</el-row>

<el-row>
  <el-button icon="el-icon-search" circle></el-button>
  <el-button type="primary" icon="el-icon-edit" circle></el-button>
  <el-button type="success" icon="el-icon-check" circle></el-button>
  <el-button type="info" icon="el-icon-message" circle></el-button>
  <el-button type="warning" icon="el-icon-star-off" circle></el-button>
  <el-button type="danger" icon="el-icon-delete" circle></el-button>
</el-row>

举例:

<template>
  <el-row>
    <el-button>我是默认按钮</el-button>
    <el-button type="primary">蓝色的按钮</el-button>
    <el-button type="success" plain>plain代表朴素</el-button>
    <el-button type="info" round>round能改变为圆角</el-button>
    <el-button type="warning"round plain>警告按钮</el-button>
    <el-button type="danger">危险危险危险</el-button>
  </el-row>
</template>

启动后:
在这里插入图片描述

4 写在最后

以上为安装,配置,使用的方法,在此简单记录一下。

相关文章
|
1天前
|
JavaScript
Vue学习之--------深入理解Vuex之多组件共享数据(2022/9/4)
这篇文章通过一个实际的Vue项目案例,演示了如何在Vuex中实现多组件间共享数据。文章内容包括在Vuex的state中新增用户数组,创建Person.vue组件用于展示和添加用户信息,以及在Count组件中使用Person组件操作的数据。通过测试效果展示了组件间数据共享和状态更新的流程。
Vue学习之--------深入理解Vuex之多组件共享数据(2022/9/4)
|
1天前
|
JavaScript 前端开发 开发者
Vue学习之--------深入理解Vuex、原理详解、实战应用(2022/9/1)
这篇文章详细介绍了Vuex的基本概念、使用场景、安装配置、基本用法、实际应用案例以及注意事项,通过一个数字累加器的实战示例,帮助开发者深入理解Vuex的原理和应用。
|
1天前
|
存储 JavaScript API
vue后台管理权限码处理
【8月更文挑战第19天】vue后台管理权限码处理
8 0
|
1天前
|
JavaScript
Vue学习之--------深入理解Vuex之getters、mapState、mapGetters(2022/9/3)
这篇文章深入探讨了Vuex中的getters概念和用法,以及如何通过mapState、mapGetters、mapActions和mapMutations四个辅助函数简化组件中的Vuex状态访问和操作,通过实际项目案例展示了这些概念的应用和效果。
|
12月前
|
JavaScript
Vue的非父子组件之间传值
全局事件总线 一种组件间通信的方式,适用于任意组件间通信
|
11月前
|
缓存 JavaScript 前端开发
Vue Props、Slot、v-once、非父子组件间的传值....
Vue Props、Slot、v-once、非父子组件间的传值....
66 0
|
12月前
|
JavaScript
Vue中父子组件传值
先在⽗组件中给⼦组件的⾃定义属性绑定⼀个⽗组件的变量
|
12月前
|
JavaScript
vue 组件传值
vue 组件传值
65 0
|
JavaScript
vue父子组件传值
vue父子组件传值
|
JavaScript
vue兄弟组件传值 方便快捷
vue兄弟组件传值 方便快捷