Element-UI快速入门(一)

简介: Element-UI快速入门

什么是Element UI


  1. Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库
  1. Element UI是基于Vue 2.0的
  2. Element UI 提供一组组件
  3. Element UI 提供组件的参考实例, 直接复制
  1. 官方网站:

https://element.eleme.cn/#/zh-CN/component/installation

搭建环境


创建项目


步骤一: 通过 vue-cli创建项目

vue create eui01

步骤二:运行项目

image.png

整合1:插件


安装好vue项目后,进入到项目目录,执行命令

vue add element

整合步骤1:确定引入方式(全部引入、按需引入)

image.png

整合2:安装element-ui插件


npm i element-ui --save

image.png

整合:element-ui引入


  1. 官方提供了2种引入方式:完整引入、按需引入
  1. 完整引入:引入了eui所有的组件,学习时/开发时常用
  2. 按需引入:引入需要的组件,生产环境下使用。
  1. 完整引入
  1. 1. 导入 element ui 组件库
  2. 2. 导入 element ui css样式
  3. 3. 并将element ui 注册给vue

image.png

/* 导入element-ui样式*/import'element-ui/lib/theme-chalk/index.css'importVuefrom'vue'importAppfrom'./App.vue'importrouterfrom'./router'importstorefrom'./store'/* element-ui所有组件*/importElementUIfrom'element-ui'Vue.use(ElementUI)
Vue.config.productionTip=falsenewVue({
router,
store,
render: h=>h(App)
}).$mount('#app')

3.布局容器


布局容器


  1. 使用element-ui的布局容器(Container) 进行页面布局。对页面进行划分(上、下、左、中)
  2. 官方文档 : https://element.eleme.cn/#/zh-CN/component/container

用于布局的容器组件,方便快速搭建页面的基本结构:

<el-container>:外层容器。当子元素中包含 <el-header> 或 <el-footer> 时,全部子元素会垂直上下排列,否则会水平左右排列。


<el-header>:顶栏容器。

<el-aside>:侧边栏容器。

<el-main>:主要区域容器。

<el-footer>:底栏容器。

以上组件采用了 flex 布局,使用前请确定目标浏览器是否兼容。此外,<el-container> 的子元素只能是后四者,后四者的父元素也只能是 <el-container>

image.png

步骤一: 修改src/main.js 导入 element-ui 样式和组件

/* 导入element-ui样式*/import'element-ui/lib/theme-chalk/index.css'importVuefrom'vue'importAppfrom'./App.vue'importrouterfrom'./router'importstorefrom'./store'/* element-ui所有组件*/importElementUIfrom'element-ui'Vue.use(ElementUI)
Vue.config.productionTip=falsenewVue({
router,
store,
render: h=>h(App)
}).$mount('#app')

步骤二: 删除 src/App.vue所有内容, 拷贝布局模板和样式

<template><divid="app"><el-container><el-header>Header</el-header><el-main>Main</el-main><el-footer>Footer</el-footer></el-container></div></template><script>exportdefault {
}
</script><style>/* 稍后删除 */  .el-header, .el-footer {
background-color: #B3C0D1;
color: #333;
text-align: center;
line-height: 60px;
  }
</style>

reset.css


布局页面完成后, 整个body会存在一圈空白, 开发中一般选择重新设置页面样式

image.png

步骤一: 百度搜索”reset.css” , 并创建 assets/app.css ,拷贝样式 (复制下面样式即可)

image.png

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,th,td {
margin: 0;
padding: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
fieldset,img {
border: 0;
}
address,caption,cite,code,dfn,em,strong,th,var {
font-style: normal;
font-weight: normal;
}
ol,ul {
list-style: none;
}
caption,th {
text-align: left;
}
h1,h2,h3,h4,h5,h6 {
font-size: 100%;
font-weight: normal;
}

满屏填充


在App.vue中,添加样式

1. html, body, .el-container {
2. height: 100%;
3.   }

4.导航条


需求


image.png

导航条


使用导航菜单(NavMenu) 完成导航条效果

官方文档 : https://element.eleme.cn/#/zh-CN/component/menu

image.png

<template><divid="app"><el-container><el-header><!--导航条--><el-menu          :default-active="$route.path"class="el-menu-demo"mode="horizontal"background-color="#545c64"text-color="#fff"active-text-color="#ffd04b"><el-menu-itemindex="/">首页</el-menu-item><el-submenuindex="2"><templateslot="title">学生管理</template><el-menu-itemindex="/studentList">学生列表</el-menu-item></el-submenu><el-submenuindex="3"><templateslot="title">个人中心</template><el-menu-itemindex="/login">登录</el-menu-item><el-menu-itemindex="/register">注册</el-menu-item></el-submenu><el-menu-itemindex="/cart">购物车</el-menu-item></el-menu></el-header><el-main><router-view></router-view></el-main><el-footer>版权所有2006-2022传智专修学院</el-footer></el-container></div></template><script>exportdefault {
}
</script><style>  .el-header, .el-footer {
background-color: #B3C0D1;
color: #333;
text-align: center;
line-height: 60px;
padding: 0;
  }
</style>

路由


点击”首页” 和 “购物车” 可以调整页面

image.png

image.png

image.png

image.png

<template><divid="app"><el-container><el-header><!--导航条--><el-menuclass="el-menu-demo"mode="horizontal"background-color="#545c64"text-color="#fff"active-text-color="#ffd04b"          :router="true"><el-menu-itemindex="/">首页</el-menu-item><el-submenuindex="2"><templateslot="title">学生管理</template><el-menu-itemindex="/studentList">学生列表</el-menu-item></el-submenu><el-submenuindex="3"><templateslot="title">个人中心</template><el-menu-itemindex="/login">登录</el-menu-item><el-menu-itemindex="/register">注册</el-menu-item></el-submenu><el-menu-itemindex="/cart">购物车</el-menu-item></el-menu></el-header><el-main><router-view></router-view></el-main><el-footer>版权所有2006-2020传智专修学院</el-footer></el-container></div></template><script>exportdefault {
}
</script><style>  .el-header, .el-footer {
background-color: #B3C0D1;
color: #333;
text-align: center;
line-height: 60px;
padding: 0;
  }
</style>

image.png

image.png


相关文章
|
18天前
|
JavaScript 前端开发 开发者
Element-UI快速入门
Element-UI 是一个功能强大的 Vue 组件库,非常适合快速开发高质量的企业级前端应用。通过本文的快速入门指南,你应该能够开始使用 Element-UI,并将其组件应用到你的项目中。不断探索和实践将帮助你更好地理解和利用这个工具库为你的应用增添独特的价值。 希望这篇博客能够帮助你快速上手 Element-UI,为你的 Vue 项目加速开发。
20 1
|
2天前
|
JavaScript 前端开发 UED
Element UI 表单验证详解与实践
Element UI 表单验证详解与实践
4 0
|
1月前
|
JavaScript Windows
Element-ui快速入门
Element-ui快速入门
20 0
|
1月前
|
容器
基于element-ui的侧边栏及其使用方法
基于element-ui的侧边栏及其使用方法
96 0
|
1月前
|
资源调度 JavaScript 开发者
如何强制安装element-ui
如何强制安装element-ui
40 0
|
6月前
|
前端开发 JavaScript CDN
【 Element UI 】—Element UI 的基本使用
【 Element UI 】—Element UI 的基本使用
|
1月前
|
前端开发 JavaScript 数据库
Element-UI(增删改查)
Element-UI(增删改查)
78 0
|
8月前
Element-UI快速入门 (二)
5.表格:查询列表 测试页面
48 0
|
8月前
|
前端开发
Element-UI快速入门 (三)
7.常见组件 按钮 Button
34 0
|
8月前
|
JavaScript 前端开发 开发者
Element-UI快速入门(一)
什么是Element UI Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组件库 Element UI是基于Vue 2.0的 Element UI 提供一组组件 Element UI 提供组件的参考实例, 直接复制
129 0