子控件Header.vue <script> export default { name: "Header", methods:{ toUser(){ console.log('user') }, toExit(){ console.log('exit') }, collapse(){ //传值方法 this.$emit('doCollapse') } } } </script>
父控件Index.vue
<template> <el-container style="height: 100%; border: 1px solid #eee"> <el-aside width="200px" style="background-color: rgb(238, 241, 246);height: 100%;margin-left: -1px;" > <Aside :isCollapse="isCollapse"></Aside> </el-aside> <el-container style="height: 100%"> <el-header style="text-align: right; font-size: 12px;border-bottom: rgba(169,169,169,0.3) 1px solid"> <Header @doCollapse="doCollapse"></Header> </el-header> <el-main style="height: 100%"> <Main></Main> </el-main> </el-container> </el-container> </template> <script> import Aside from "./Aside"; import Header from "./Header"; import Main from "./Main"; export default { name: "Index", components: {Main, Header, Aside}, data(){ return{ isCollapse:false } }, methods:{ doCollapse(){ console.log('11') this.isCollapse=!this.isCollapse } } } </script> <style scoped> .el-header { /*background-color: #B3C0D1;*/ color: #333; line-height: 60px; } .el-aside { color: #333; } .el-main { padding: 5px; } </style>