JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui/lib/index.js"></script>
<div id="app">
<el-row class="tac">
<el-col :span="leftSpan" :class="{ 'hide': !expanded }">
<el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose">
<el-menu-item index="1">
<i class="el-icon-message"></i>
<span>导航一</span>
</el-menu-item>
<el-menu-item index="2">
<i class="el-icon-menu"></i>
<span>导航二</span>
</el-menu-item>
<el-menu-item index="3">
<i class="el-icon-setting"></i>
<span>导航三</span>
</el-menu-item>
</el-menu>
</el-col>
<el-col :span="rightSpan">
<div class="main">
<i :class="[`el-icon-d-arrow-${ icon }`, 'icon']" @click="expanded = !expanded"></i>
页面内容
</div>
</el-col>
</el-row>
</div>
SCSS
@import url("//unpkg.com/element-ui/lib/theme-default/index.css");
body {
margin: 0;
}
html, body, #app, .el-row, .el-col, .el-menu, .main {
height: 100%;
}
.el-col {
transition: 100ms;
}
.main {
text-align: center;
position: relative;
background-color: #ddd;
padding-top: 100px;
}
.icon {
position: absolute;
left: 10px;
top: 10px;
}
.hide [class^=el-icon-] {
font-size: 26px;
vertical-align: middle;
margin-right: 0;
}
.hide span {
display: none;
}
Babel + JSX
var Main = {
data() {
return {
expanded: true
}
},
computed: {
icon() {
return this.expanded ? 'left' : 'right'
},
leftSpan() {
return this.expanded ? 8 : 3
},
rightSpan() {
return this.expanded ? 16 : 21
}
},
methods: {
handleOpen(key, keyPath) {
console.log(key, keyPath);
},
handleClose(key, keyPath) {
console.log(key, keyPath);
}
}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')