使用对象的语法,键对应的就是实际的 calss 值,值对应的是 true 或 false
使用数组的语法,值对应的是 vue data 里面的此值对应的值
style 就相当于是直接在这里写了 style
<html>
<head>
<meta charset="utf-8">
<title>Vue class与style测试</title>
<script src="https://cdn.bootcss.com/vue/1.0.14/vue.min.js"></script>
<style>
.red {
background: red;
width: 100px;
height: 100px;
}
.green {
background: green;
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="app">
<p>对象语法</p>
<div v-bind:class="{red:true}">显示红色区块</div>
<div v-bind:class="{red:false}">不显示</div>
<div v-bind:class="{red:hide}">值是变量</div>
<p>数组语法</p>
<div v-bind:class="[green_color]">不显示</div>
<p>style 测试</p>
<div v-bind:style="styleObject"></div>
</div>
<script>
new Vue({
el: '#app',
data: {
hide:false,
green_color:'green',
styleObject: {
background: 'blue',
fontSize: '13px',
height:'100px',
width:'100px',
}
}
});
</script>
</body>
</html>
网友评论