将 isActive 设置为 true 显示了一个绿色的 div 块,如果设置为 false 则不显示:
<!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" />
<script src="https://unpkg.com/vue@next"></script>
<title>Document</title>
<style>
.active {
width: 100px;
height: 100px;
background: green;
}
</style>
</head>
<body>
<div id="app">
<div :class="{ 'active': isActive }"></div>
</div>
<script>
const app = {
data() {
return {
isActive: true,
}
},
}
Vue.createApp(app).mount('#app')
</script>
</body>
</html>

本文来自博客园,作者:wjxuriel,转载请注明原文链接:https://www.cnblogs.com/my-blog-site/p/16203202.html

浙公网安备 33010602011771号