class樣式綁定:
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供膠州網(wǎng)站建設、膠州做網(wǎng)站、膠州網(wǎng)站設計、膠州網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、膠州企業(yè)網(wǎng)站模板建站服務,10年膠州做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./vue.js"></script>
<!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
<style type="text/css">
.activated{
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<div id="app">
<div @click="handleDivClick" :class="{activated: isActivated}"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
isActivated: false
},
methods: {
handleDivClick: function() {
this.isActivated = !this.isActivated
}
}
})
</script>
</body>
</html>
數(shù)組變量的綁定
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./vue.js"></script>
<!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
<style type="text/css">
.activated{
color: red;
font-weight: bold;
}
</style>
</head>
<body>
<!-- <div id="app">
<div @click="handleDivClick" :class="{activated: isActivated}"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
isActivated: false
},
methods: {
handleDivClick: function() {
this.isActivated = !this.isActivated
}
}
})
</script> -->
<div id="app">
<div @click="handleDivClick" :class="[activated]"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
activated: ""
},
methods: {
handleDivClick: function() {
if (this.activated === "activated") {
this.activated = "";
}else {
this.activated = "activated";
}
}
}
})
</script>
</body>
</html>
style綁定:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./vue.js"></script>
<!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
</head>
<body>
<!-- <div id="app">
<div @click="handleDivClick" :class="{activated: isActivated}"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
isActivated: false
},
methods: {
handleDivClick: function() {
this.isActivated = !this.isActivated
}
}
})
</script> -->
<div id="app">
<div : @click="handleDivClick"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
styleObj: {
color: "black"
}
},
methods: {
handleDivClick: function() {
if (this.styleObj.color == "black") {
this.styleObj.color = "red"
}else {
this.styleObj.color = "black"
}
}
}
})
</script>
</body>
</html>
style數(shù)組綁定:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./vue.js"></script>
<!-- <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script> -->
</head>
<body>
<!-- <div id="app">
<div @click="handleDivClick" :class="{activated: isActivated}"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
isActivated: false
},
methods: {
handleDivClick: function() {
this.isActivated = !this.isActivated
}
}
})
</script> -->
<!-- <div id="app">
<div : @click="handleDivClick"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
styleObj: {
color: "black"
}
},
methods: {
handleDivClick: function() {
if (this.styleObj.color == "black") {
this.styleObj.color = "red"
}else {
this.styleObj.color = "black"
}
}
}
})
</script> -->
<div id="app">
<div : @click="handleDivClick"><h2>hello world</h2></div>
</div>
<script type="text/javascript">
var vm = new Vue({
el: "#app",
data: {
styleObj: {
color: "black",
border:"1px solid red"
}
},
methods: {
handleDivClick: function() {
if (this.styleObj.color == "black") {
this.styleObj.color = "red"
}else {
this.styleObj.color = "black"
}
}
}
})
</script>
</body>
</html>
分享題目:Vue中的樣式綁定
當前路徑:http://www.rwnh.cn/article2/jeshic.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、服務器托管、關鍵詞優(yōu)化、網(wǎng)站設計、網(wǎng)站改版、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)