vue233/03-v-bind动态属性绑定/bind类属性的使用.html

57 lines
1.1 KiB
HTML

<!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">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
font-size: 22px;
}
.active{
color: #f00;
font-weight: bolder;
}
.btn{
color: #00f;
}
button{
font-size: 16px;
}
</style>
</head>
<body>
<div id="app">
<div :class="cons()">{{content}}</div>
<button v-on:click="change()" :class="btns()">点击我变色</button>
</div>
<script src="../00-tools/JavaScript/vue.js"></script>
<script>
let vue=new Vue({
el:"#app",
data:{
content:"欢迎你",
isActive:true,
isbtn:false
},
methods: {
change:function(){
this.isActive=!this.isActive
this.isbtn=!this.isbtn
},
cons:function(){
return {active:this.isActive}
},
btns:function(){
return {btn:this.isbtn}
}
},
})
</script>
</body>
</html>