class与style绑定
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> class与style绑定</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
<div id="app">
<div class="test" v-bind:class="{ active : isActive , green : isGreen}"
style="width:200px; height:200px; text-align:center; line-height:200px;">
hello
</div>
<div :style="{color : color, fontSize:size, background: bool ? 'green' : '' }">
hello
</div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: '#app',
data: {
isActive: true,
isGreen: true,
color: 'red',
size: '50px',
bool: true,
},
})
</script>
<style>
.test {
font-size: 30px;
}
.green {
color: green;
}
.active {
background: red;
}
</style>
</body>
</html>
效果图