<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="../js/vue.js"></script> <style> .static { border: 1px solid black; background-color: aquamarine; } .big { width: 200px; height: 200px; } .small { width: 100px; height: 100px; } </style> </head> <body> <div id="app"> <h1>{{msg}}</h1> <!-- 静态写法 --> <div class="static small">{{msg}}</div> <br><br> <button @click="changeBig">变大</button> <button @click="changeSmall">变小</button> <!-- 动态写法 --> <div class="static" v-bind:class="c">{{msg}}</div> </div> <script> const vm = new Vue({ el : "#app", data : { msg : "Hello", c : "big" }, methods : { changeBig() { this.c = "big"; }, changeSmall() { this.c = "small"; } } }); </script> </body> </html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../js/vue.js"></script>
<style>
.static
{
border: 1px solid black;
background-color: aquamarine;
}
.big
{
width: 200px;
height: 200px;
}
.small
{
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<div id="app">
<h1>{{msg}}</h1>
<!-- 静态写法 -->
<div class="static small">{{msg}}</div>
<br><br>
<button @click="changeBig">变大</button>
<button @click="changeSmall">变小</button>
<!-- 动态写法 -->
<div class="static" v-bind:class="c">{{msg}}</div>
</div>
<script>
const vm = new Vue({
el : "#app",
data : {
msg : "Hello",
c : "big"
},
methods : {
changeBig()
{
this.c = "big";
},
changeSmall()
{
this.c = "small";
}
}
});
</script>
</body>
</html>
VUE框架使用字符串的形式实现对class的绑定效果达到动态css样式------VUE框架
于 2023-11-29 11:21:50 首次发布