内联样式的基本语法:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<div style="width: 100px;height: 100px;background: blue;"></div>
<!-- CSS内联样式变量拼接 -->
<div style="width: 100px;height: 100px;background: blue;"
:style="{border:borderw+'px solid red',padding:paddingw+'px'}"></div>
<!-- CSS内联样式放置对象 -->
<div :style="styleoObj"></div>
<!-- CSS数组方式拼接 -->
<div :style="styleArr"></div>
</div>
<script type="text/javascript">
let app = new Vue({
el:"#app",
data:{
borderw:50,
paddingw:20,
styleoObj:{
width:"200px",
height:"300px",
padding:"50px",
"background-color":"yellow"
},
styleArr:[
{
width:"200px",
height:"300px",
padding:"50px",
"background-color":"blue"
},
{
border:"30px solid red"
}
]
}
})
</script>
</body>
</html>
侧边栏class
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
*{
margin:0;
padding:0;
box-sizing: border-box;
}
.page{
width: 100vw;
height: 100vh;
background-color: bisque;
position: fixed;
left: 0;
top: 0;
}
.rMenu{
width: 50vw;
height: 100vw;
position: fixed;
left: 0;
top: 0;
background-color: aqua;
transform: translateX(100vw);
transition: transform 0.5s;
}
.active{
transform: translateX(80vw);
}
</style>
</head>
<body>
<div id="app">
<div class="page">
首页
<button @click="toggleMenu" type="button">侧边栏</button>
</div>
<div class="rMenu" :class="{active:isShow}">
侧边栏
</div>
</div>
<script type="text/javascript">
let app = new Vue({
el:"#app",
data:{
isShow:false
},
methods:{
toggleMenu:function(){
this.isShow = !this.isShow
}
}
})
</script>
</body>
</html>
侧边栏style
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
*{
margin:0;
padding:0;
box-sizing: border-box;
}
.page{
width: 100vw;
height: 100vh;
background-color: bisque;
position: fixed;
left: 0;
top: 0;
}
.rMenu{
width: 50vw;
height: 100vw;
position: fixed;
left: 0;
top: 0;
background-color: aqua;
transform: translateX(100vw);
transition: transform 0.5s;
}
/* .active{
transform: translateX(80vw);
}
*/
</style>
</head>
<body>
<div id="app">
<div class="page">
首页
<button @click="toggleMenu" type="button">侧边栏</button>
</div>
<div class="rMenu" :style="{transform: 'translateX('+men+'vw)'}">
侧边栏
</div>
</div>
<script type="text/javascript">
let app = new Vue({
el:"#app",
data:{
men:100
},
methods:{
toggleMenu:function(){
if(this.men==100){
this.men = 80
}else{
this.men = 100
}
}
}
})
</script>
</body>
</html>