使用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>
网友评论