绑定样式(动态切换样式)
2018-08-19 本文已影响0人
九尾的日志
使用v-bind绑定class,实现动态的样式切换
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>绑定样式</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<div v-bind:class="yellow"></div>
<div v-bind:class="[yellow,red]"></div>
<div v-bind:class="{yellow:status}"></div>
</div>
<style>
.yellow {
width: 200px;
height: 200px;
background: #ff0;
}
.red {
width: 200px;
height: 200px;
background: red;
}
</style>
<script>
var vm = new Vue({
el: '#app',
data: {
yellow : 'yellow',
red : 'red',
status : true
}
})
</script>
</body>
</html>