<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue测试实例</title>
</head>
<style>
.class1{
color:red;
}
</style>
<body>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<div id="app">
<!-- v-bind绑定class 使用对象 对象键(类名):对象值(布尔值)-->
<h2 v-bind:class="{'class1':isActive}">{{ message }}</h2>
<button v-on:click="btnclick">按钮</button>
</div>
<script>
new Vue({
el: '#app',
data:{
message:"hello",
isActive:false
},
methods:{
btnclick:function(){
this.isActive = !this.isActive
}
}
});
</script>
</body>
v-bind绑定class
最新推荐文章于 2024-04-24 12:45:34 发布