A brief taste of vue
Foreword:
I found a lot of information on the Internet about custom form objects for loop processing. I was confused by what was written. In the end, I directly modified the component to improve it, and directly used v-for for loop binding to implement it. This example implements a custom menu bar and vue-router routing to point to the menu and perform routing jumps, which is mainly implemented by the el-menu component.
Custom objects must be configured with paths for routing jumps
This example project structure:
Idea:
The main purpose is to implement the construction of the continer framework in app.vue, and to implement page jumps in the contatiner to locate the customized components. The total component I positioned at this location is menutree.vue, and put <router-view/> In this component, when the route needs to jump, the component is directly positioned and modified.
Key points:
Here is the link that mainly solves the menu bar jump
1. To implement route jump, first add the router attribute to the el-menu tag, and then just set the url in the index attribute in each el-menu-item tag to click el-menu-item to realize the route jump. change.
2. Navigate the current item and bind it in the el-menu tag: default-active="$route.path". Note that it is a binding attribute. Don't forget to add
Code:
vue+elementui project el-menu navigation bar implements routing jump and setting of current item_elementui menu routing_Blog between the North and South Pole-CSDN Blog
<template>
<el-container style="height: 1000px; border: 1px solid #eee">
<el-aside width="200px" style="background-color: rgb(238, 241, 246)">
<el-menu
router
:default-active="$route.path"
:default-openeds="['1', '3']" v-for="(item,index) in menuList" :key="index">
<el-sub-menu index="{
{item.id}}">
<template #title><i class="el-icon-message"></i>{
{item.name}}</template>
<el-menu-item-group :title="item.name">
<el-menu-item v-for="(val,index1) in item.childs" :key="index1" :index="val.path">{
{val.name}}</el-menu-item>
</el-menu-item-group>
</el-sub-menu>
</el-menu>
</el-aside>
<el-container>
<el-header style="text-align: right; font-size: 12px height=100px">
<el-dropdown>
<i class="el-icon-setting" style="margin-right: 15px"></i>
<template #dropdown>
</template>
</el-dropdown>
</el-header>
<el-container class="fonter-page">
<menutree/>
</el-container>
</el-container>
</el-container>
</template>
<script>
import MenuTree from './components/MenuTree.vue'
export default {
name: 'App',
components:{
menutree:MenuTree
},
data(){
return {
menuList:[
{
id:1,
name:'数据概况',
childs:[
{
id:1,
name:'全局统计',
path:'/path/globalgeneral'
}
]
},
{
id:2,
name:'访问分析',
childs:[
{
id:1,
name:'用户趋势',
path:'/path/tendency'
}
]
},
{
id:3,
name:'用户质量',
childs:[
{
id:1,
name:'分析留存',
path:'/path/save'
}
]
},
{
id:4,
name:'用户画像',
childs:[
{
id:1,
name:'性别分析',
path:'/path/male'
},
{
id:2,
name:'年龄分析',
path:'/path/age'
}, {
id:3,
name:'地域分析',
path:'/path/area'
}, {
id:4,
name:'设备分析',
path:'/path/equipment'
},
]
},
]
}
}
}
</script>
<style>
html,body,#app{
height:100%;
margin: 0px;
padding: 0px;
}
.el-header {
background-color: #f8f8f6;
color: var(--el-text-color-primary);
line-height: 60px;
}
.el-aside {
color: var(--el-text-color-primary);
}
.fonter-page{
background-color: rgb(142, 169, 182);
height: 500px;
width: 800%;
padding-top: 200px;
}
</style>