简单类名绑定
先来看一个简单实例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>动态添加样式</title>
<style>
.first {
background-color: blueviolet;
}
.second {
display: block;
width: 240px;
height: 240px;
background-color: rgb(208, 226, 43);
}
.third {
display: block;
width: 640px;
height: 240px;
background-color: rgb(43, 116, 226);
}
</style>
</head>
<body>
<script src="../third_party_pack/vue/vue.js"></script>
<div id="sagasw">
<div class="first" @click="real=!real" :class="{second:real,third:!real}">123</div>
</div>
<script>
new Vue({
el: '#sagasw',
data: {
real: false,
}
})
</script