概要
简易vue + element ui界面
大概内容
1.快速创建vue项目
2.设置div+css样式
3.强制设置element ui中样式
4.使用iconfont.cn中图标
5.全屏显示
技术名词解释
!important:强制生效
.el-submenu .el-menu-item {
background-color: #000c17 !important;
/**!important:强制生效 */
}
技术细节
一、
快速创建vue项目
1.vue install -g @vue/cli 全局安转
2.vue create ‘项目名称’
3.选择Manually select features (Babel\Router)
4.创建2.X
5.cd 项目目录
6.npm run serve运行即可
二、设置div+css样式
直接在div中设置
<div style="height: 60px; display: flex; justify-content:center;align-items:center;color: white;">
<img src="@/assets/96.png" style="width: 40px;">
<span class="log-title" v-show="!isCollapse">honey 2024</span>
</div>
在style中设置
.el-submenu .el-menu-item {
background-color: #000c17 !important;
/**!important:强制生效 */
}
三、强制设置element ui中样式
!important:强制生效
四.使用iconfont.cn中图标
访问iconfont.cn网址,找到要下载的图标加入购物车

在购物车中添加至项目
项目设置需要更改的内容

进行下载

将这4个文件导入到自己的项目中 src/assets/css/iconfont下(/css/iconfont)自己创建的文件夹
在main.js中引入import ‘@/assets/css/iconfont/iconfont.css’
在页面中使用
<i class="el-icon-quanping_o" style="font-size: 35px;" @click="handleful"></i> //el-icon-quanping_o:在iconfont.css中:before前的内容
handleful(){
document.documentElement.requestFullscreen() //全屏
}
代码
<template>
<div>
<el-container>
<!--侧边栏-->
<el-aside :width="asideWidth" style="min-height: 100vh; background-color:#001529;">
<div style="height: 60px; display: flex; justify-content:center;align-items:center;color: white;">
<img src="@/assets/96.png" style="width: 40px;">
<span class="log-title" v-show="!isCollapse">honey 2024</span>
</div>
<!--加上 router关键字 就可以实现跳转了-->
<el-menu :collapse="isCollapse" :collapse-transition="false" router background-color="#001529"
text-color="rgba(255,255,255,0.65)" active-text-color="#fff" style="border:none;"
:default-active="$route.path"> <!--route.path 当前浏览器正在访问的路由-->
<el-menu-item index="/"> <!--只有el-menu-item 才能生效 index需要与router index.js匹配-->
<i class="el-icon-house"></i>
<span slot="title">系统首页</span>
</el-menu-item>
<el-menu-item index="/element">element页面</el-menu-item>
<el-menu-item>系统首页</el-menu-item>
<el-menu-item>系统首页</el-menu-item>
<el-submenu>
<template slot="title">
<i class="el-icon-menu"></i>
<span>信息管理</span>
</template>
<el-menu-item>用户信息</el-menu-item>
<el-menu-item>学生信息</el-menu-item>
</el-submenu>
</el-menu>
</el-aside>
<el-container>
<!--头部区域-->
<el-header>
<i :class="collapseIcon" style="font-size: 25px;" @click="handleCollapse"></i>
<el-breadcrumb separator-class="el-icon-arrow-right" style="margin-left: 20px;">
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item :to="{ path: '/element' }">用户管理</el-breadcrumb-item>
</el-breadcrumb>
<div style="flex: 1;width: 0; display: flex; align-items: center;justify-content: flex-end;">
<i class="el-icon-quanping_o" style="font-size: 35px;" @click="handleful"></i>
<el-dropdown placement="bottom">
<div style="display: flex; align-items: center; cursor: default;">
<img src="@/assets/96.png" style="width:40px;height: 40px;margin-left: 10px;">
<span>管理员</span>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>个人信息</el-dropdown-item>
<el-dropdown-item>修改密码</el-dropdown-item>
<el-dropdown-item>退出登录</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-header>
<!--主体-->
<el-main>主体</el-main>
</el-container>
</el-container>
</div>
</template>
<script>
export default {
data() {
return {
isCollapse: false, //不收缩
asideWidth: '200px',
collapseIcon: 'el-icon-s-fold'
}
},
methods: {
handleCollapse() {
this.isCollapse = !this.isCollapse,
this.asideWidth = this.isCollapse ? '64px' : '200px'
this.collapseIcon = this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'
},
handleful(){
document.documentElement.requestFullscreen() //全屏
}
}
}
</script>
<style>
.el-submenu .el-menu-item {
background-color: #000c17 !important;
/**!important:强制生效 */
}
.el-menu-item:hover,
.el-submenu__title:hover {
color: #fff !important;
}
.el-menu-item.is-active {
background-color: #1890ff !important;
border-radius: 4px !important;
margin: 4px !important;
}
.el-menu-item {
height: 40px !important;
line-height: 40px !important;
margin: 4px !important;
}
.el-submenu__title {
height: 40px !important;
line-height: 40px !important;
margin: 4px !important;
}
.el-menu--inline {
background-color: #000c17 !important;
}
.log-title {
margin-left: 5px;
transition: all .10s;
}
.el-header {
box-shadow: 2px 0 6px rgba(0, 21, 41, .35);
display: flex;
align-items: center;
}
</style>

简易Vue+ElementUI项目构建与样式定制教程

本文详细介绍了如何使用Vue和ElementUI创建项目,包括快速搭建、CSS样式设置、ElementUI样式强制应用、Iconfont图标使用以及全屏功能实现。还展示了VueCLI的配置和组件结构,如侧边栏菜单和头部导航的设计。
347





