<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>JavaScript_expression</title>
</head>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.page{
width: 100vw;
height: 100vh;
color: #fff;
position: fixed;
background-color: red;
}
.rMenu{
width: 50vw;
height: 100vh;
position: fixed;
left: 0;
top: 0;
transform: translateX(100vw);
background: #008000;
transition: transform 3s;
}
.active{
transform: translateX(50vw);
}
</style>
<body>
<div id='app'>
<div class="page">
<div>
<button @click="toggleMenu">切换侧边栏</button>
</div>
</div>
<div class="rMenu" :class="{active:isShow}">
侧边栏
</div>
</div>
</body>
</html>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
isShow: false
},
methods: {
toggleMenu: function() {
this.isShow = !this.isShow
}
}
})
</script>
效果: