样式细节
font-weight: 700; //字体粗细
letter-spacing: 3px; //字与字之间的间距
border-radius: 50%; //圆形
项目创建
项目创建
加入Element -UI
npm 安装 npm i element-ui -S
全部导入 在main.js
文件中加入以下代码
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)
创建.prettierrc
文件,键入下列内容:
{
"semi": false,
"singleQuote": true,
"trailingComma": "none"
}
在.eslintrc.js
rules中加入
'space-before-function-paren' : 0
改造项目
1.在src目录下新建layout
全局布局文件夹。
2.将 Home移动到 layout
,对应修改router\index.js
文件中的引用路径
3.删除 helloword.vue
测试element-ui的引入是否成功
在home.vue
中插入一段关于element-ui的代码 图中
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png" />
<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>
</div>
</template>
<script>
export default {
name: 'Home'
}
</script>
搭建基本结构
项目初始化
各大主流网站css初始化代码
css 初始化 创建 src\assets\css\reset.css
创建自己的样式文件 index.less
html,
body {
height: 100%;
}
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video{
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
font-weight: normal;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section{
display: block;
}
ol, ul, li{
list-style: none;
}
blockquote, q{
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after{
content: '';
content: none;
}
table{
border-collapse: collapse;
border-spacing: 0;
}
/* custom */
a{
color: #7e8c8d;
text-decoration: none;
-webkit-backface-visibility: hidden;
}
::-webkit-scrollbar{
width: 5px;
height: 5px;
}
::-webkit-scrollbar-track-piece{
background-color: rgba(0, 0, 0, 0.2);
-webkit-border-radius: 6px;
}
::-webkit-scrollbar-thumb:vertical{
height: 5px;
background-color: rgba(125, 125, 125, 0.7);
-webkit-border-radius: 6px;
}
::-webkit-scrollbar-thumb:horizontal{
width: 5px;
background-color: rgba(125, 125, 125, 0.7);
-webkit-border-radius: 6px;
}
html, body{
width: 100%;
font-family: "Arial", "Microsoft YaHei", "黑体", "宋体", "微软雅黑", sans-serif;
}
body{
line-height: 1;
-webkit-text-size-adjust: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
html{
overflow-y: scroll;
}
/*清除浮动*/
.clearfix:before,
.clearfix:after{
content: " ";
display: inline-block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix{
*zoom: 1;
}
/*隐藏*/
.dn{
display: none;
}
在main.js中引入样式,注意:样式文件都放在asset
里面,注意引入的顺序。
import Vue from 'vue'
import App from './App.vue'
import router from './router'
// 引入初始化css文件
import './assets/css/reset.css'
// 引入element-ui
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 引入自己定义的主样式文件
import './assets/css/index.less'
// 引入字体图标文件
import './assets/fonts/iconfont.css' //使用<p class="iconfont icon-renwu">123</p>
Vue.use(ElementUI)
Vue.config.productionTip = false
new Vue({
router,
render: (h) => h(App)
}).$mount('#app')
创建大路由和主页面
当前目录中已有的部件
layout中 Home.vue
views中 About.vue
Error.vue
Login.vue
并在router/index.js中设置了访问路径。
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../layout/Home.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/home'
},
{
path: '/home',
name: 'Home',
component: Home
},
{
path: '/login',
name: 'Login',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Login.vue')
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ '../views/About.vue')
},
{
path: '*',
redict: '/404'
},
{
path: '/404',
name: 'Error',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Error.vue')
}
]
const router = new VueRouter({
routes
})
export default router
改造登录页面Login.vue
对齐弹性容器中的弹性项目
在 vue 的单文件组件中,没有办法给编译之后的盒子加样式,如果想加,那么有两种方式:
方法一,在全局的 index.less 中找到编译之后的类名或者标签,定义全局的样式。
方法二,在当前的组件中,使用 穿刺的写法。
样式使用的总结
如果是将来也需要用到的样式,那么可以声明到 index.less 全局样式中<br /> 如果只是局部生效,那么就可以使用穿刺的写法 (注意:先去观察盒子结构,以**最终编译的结果**为准)<br /> 在 style 标签中,如果想使用less的语法,一定要加上 lang="less", 不加的话,默认是css<br /> 如果是希望当前的样式私有化,那么一定要加上 scoped 属性,不然会影响其他页面。
表单使用的介绍
数据对象、规则对象、ref (获取DOM元素)<br /> 数据对象通过 :model 绑定在表单 el-form 上,所有表单元素的 v-model 都是来源这里的数据<br /> 规则对象通过 :rules 绑定在表单 el-form 上,在所有的 el-from-item 中使用 prop 进行绑定<br /> 如果有规则,一定保证规则的属性和数据对象的属性一致<br /> ref 这个用来操作DOM,将来点击事件会使用该元素调用对应的方法<br /> 在默认的方法中,使用事件传参的方式进行调用<br />**export导出需要解构。{a,b}**
完成首页基本布局Home.vue
在Element-UI中选一个容器布局 (aseide header main footer)
.el-submenu.is-opened {
li {
background-color: #202f3f !important;
}
}
给aseide 添加NavMen.vue 导航组件
复制
logo处理
.logo {
display: flex;
justify-content: center; //居中
align-content: center;
align-items: center;
padding: 10px 0;
// 添加小手
cursor: pointer;
// 取消双击选中
-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit浏览器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期浏览器*/
user-select: none;
img {
width: 50px;
height: 50px;
border-radius: 50%; //圆形
}
h3 {
color: #fff;
margin-left: 10px;
font-weight: 700;
letter-spacing: 3px; //字与字之间的间距
}
css双击取消选中文字
div{
-moz-user-select:none;/*火狐*/
-webkit-user-select:none;/*webkit浏览器*/
-ms-user-select:none;/*IE10*/
-khtml-user-select:none;/*早期浏览器*/
user-select:none;
}
折叠菜单显示
结构创建在了 el-aside 里面,目的就是将来点击标题的时候,能够控制自己和 aside 的宽度
<el-aside :width="isCollapse ? '64px' : '200px'">
<!-- 首页标题 -->
<div class="logo" @click="isCollapse = !isCollapse">
<img src="../assets/images/logo.jpg" alt="" />
<h3 v-show="!isCollapse">外卖商家中心</h3>
</div>
<!-- 侧边栏部分 -->
<NavMenu :bool="isCollapse" /> //给子组件传递参数
</el-aside>
<!-- 省略了在data中声明 isCollapse 为 false 的值 -->
注意在子组件中接收的方式
<el-menu
default-active="2"
class="el-menu-vertical-demo"
@open="handleOpen"
@close="handleClose"
background-color="#304156"
text-color="#fff"
active-text-color="#1989fa"
:collapse="bool"
:collapse-transition="false"
>
<script>
export default {
props: { //接收父组件的参数
bool: {
type: Boolean,
default: false
}
}
}
</script>
剩下的就是美化一下样式
.logo {
display: flex;
justify-content: center;
align-items: center;
padding: 10px 0;
// 取消文字选择
-moz-user-select: none; /*火狐*/
-webkit-user-select: none; /*webkit浏览器*/
-ms-user-select: none; /*IE10*/
-khtml-user-select: none; /*早期浏览器*/
user-select: none;
// 添加小手
cursor: pointer;
img {
width: 40px;
height: 40px;
border-radius: 50%;
}
h3 {
color: #fff;
margin-left: 10px;
letter-spacing: 3px;
}
}
5.1 header 部分的布局
header 的部分创建,还是新建到 components 中去,然后以子组件的方式引入到 Home 中
5.2 Main 页面的创建
1 建 2 配 3 测试
- Dashboard.vue 后台首页
- Order.vue 订单管理
- Product 商品管理
- Index.vue 主路由文件(二级)
- ProList.vue 商品列表
- ProAdd.vue 商品添加
- ProCate.vue 商品分类
- Shop.vue 店铺管理
- Account 账号管理
- Index.vue 主路由文件(二级)
- AccountList.vue 账号列表
- AccountAdd.vue 添加账号
- ResetPwd.vue 密码重置
- SellCount 销售统计
- Index.vue 主路由文件(二级)
- GoodsCount.vue 商品统计
- OrdersCount.vue 订单统计
创建上述页面,并配置路由的配置
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../layout/Home.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
redirect: '/home'
},
{
path: '/home',
name: 'Home',
component: Home,
redirect: '/dashboard',
// 配置二级路由
children: [
{
path: '/dashboard',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Dashboard/index.vue')
},
{
path: '/pro',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Product/index.vue'),
children: [
{
path: '/pro/List', // 二级路由需加一级路由地址
component: () =>
import(
/* webpackChunkName: "about" */ '../views/Product/proList.vue'
)
},
{
path: '/pro/add',
component: () =>
import(
/* webpackChunkName: "about" */ '../views/Product/ProAdd.vue'
)
},
{
path: '/pro/cate',
component: () =>
import(
/* webpackChunkName: "about" */ '../views/Product/ProCate.vue'
)
}
]
},
{
path: '/shop',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Shop/index.vue')
}
]
},
{
path: '/login',
name: 'Login',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Login.vue')
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */ '../views/About.vue')
},
{
path: '*',
redirect: '/404'
},
{
path: '/404',
name: 'Error',
component: () =>
import(/* webpackChunkName: "about" */ '../views/Error.vue')
}
]
const router = new VueRouter({
routes
})
export default router
完成导航
NavMenu 导航菜单 添加:router="true"
,替换index = “路由路径” 。
<el-menu
default-active="/dashboard" // 默认展示
:default-active="$route.path"
class="el-menu-vertical-demo"
@open="handleOpen"
@close="handleClose"
background-color="#304156"
text-color="#fff"
active-text-color="#1989fa"
:collapse="bool"
:collapse-transition="false"
:router="true"
>