<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<style>
.active1 {
width: 100px;
height: 100px;
background: green;
}
.active2 {
width: 100px;
height: 100px;
background: red;
}
</style>
</head>
<body>
<div id="app">
<div class="static"
v-bind:class="{ 'active1': isActive1, 'active2': isActive2 }"> //谁是true,就显示谁的样式
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
isActive1: true,
isActive2: true //均为false则无样式,均为true则显示后者的样式
}
})
</script>
</body>
Vue样式绑定(切换样式)
最新推荐文章于 2024-07-16 07:16:59 发布