(1)定義布局MainLayout
<template>
<el-container>
<el-header>
<TopMenu style="height: 100%; background-color: rgb(84, 92, 100);" />
</el-header>
<el-main style="position: fixed; width: 100%; top: 60px; bottom: 0; left : 0; right: 0">
<router-view />
</el-main>
</el-container>
</template>
<script>
import { TopMenu } from "../components";
export default {
name: "MainLayout",
components: {
TopMenu,
},
};
</script>
<style lang="scss" scoped>
.el-header {
padding: 0;
}
</style>
(2)組件頁面TopMenu.vue
<template>
<div style="background-color: rgb(84, 92, 100);">
<div class="logo">
<img style="height: 100%" src="@/assets/404_images/404.png">
</div>
<el-menu mode="horizontal" class="topMenu" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
<el-menu-item index="1" @click="newPatient">新建病歷</el-menu-item>
<el-menu-item index="2">病歷查詢</el-menu-item>
<el-menu-item index="3">樣本入庫</el-menu-item>
<el-menu-item index="4">樣本出庫</el-menu-item>
<el-menu-item index="5">統(tǒng)計(jì)查詢</el-menu-item>
</el-menu>
<el-menu mode="horizontal" class="topActions" background-color="#545c64">
<el-menu-item>
<el-input placeholder="搜索患者">
<el-button slot="append" icon="el-icon-search" />
</el-input>
</el-menu-item>
<el-menu-item>
<el-dropdown trigger="click">
<el-button type="text" size="mini" style="color: white">當(dāng)前用戶:{{ name }}<i class="el-icon-arrow-down el-icon--right" /></el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item>登出</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-menu-item>
</el-menu>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
data() {
return {
}
},
computed: {
...mapGetters(['name'])
},
mounted() {},
methods: {
newPatient() {
// this.$router.push('/patient/ClinicalFamilySamples/ClinicalFamilySamples_add')
this.$router.push('/OutHospitalDiagnosisAndTreatmentAdversePregnancyAndChildbirthHistory/index')
}
}
}
</script>
<style lang="scss" scoped>
.logo {
height: 100%;
float: left;
padding: 10px 20px;
}
.topMenu {
float: left;
}
.topActions {
float: right;
}
</style>
(3)使用MainLayout布局
路由index.js文件
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout */
import MainLayout from '@/layout/main'
export const constantRoutes = [
{
path: '/login',
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/404',
component: () => import('@/views/404'),
hidden: true
},
{
path: '/',
component: MainLayout,
redirect: '/dashboard',
children: [{
path: 'dashboard',
name: 'Dashboard',
component: () => import('@/views/dashboard/index'),
meta: { title: '主頁', icon: 'dashboard' },
hidden: true
}]
},
]
/**
* asyncRoutes
* the routes that need to be dynamically loaded based on user roles
*/
export const asyncRoutes = [
{
path: '/test_radio',
name: 'test_radio',
component: MainLayout,
children: [
{
path: 'index',
component: () => import('@/views/form/test_radio'),
name: 'test_radio',
meta: { title: '測試單選框' }
}
]
},
{
path: '/',
component: () => import('@/views/nested/menu2/index'),
meta: { title: 'menu2' },
hidden: true,
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => new Router({
// mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: constantRoutes
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
export default router