<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../js/vue.js"></script>
</head>
<style>
.active {
color: red;
}
</style>
<body>
<div id="app">
<div @click="handleDivClick" :class="{'active':isactive}">Hello world</div>
<div @click="handleDiv" :class="{active}">Hello world</div>
<div @click="handle" :style="styleObj">Hello world</div>
<div :style="[styleObj,{fontSize:'20px'}]">Hello world</div>
</div>
<script>
var vm = new Vue({
el: "#app",
data: {
isactive: false,
active: '',
styleObj: {
color: "black"
}
},
methods: {
handleDivClick: function() {
this.isactive = !this.isactive;
},
handleDiv() {
if (this.active === "") {
this.active = 'active';
} else {
this.active = "";
}
},
handle() {
this.styleObj.color = this.styleObj.color === "black" ? "red" : "black";
}
}
})
</script>
</body>
</html>
vue样式绑定
最新推荐文章于 2024-06-30 10:00:38 发布