|
|
@ -4,57 +4,83 @@ |
|
|
|
<meta charset="UTF-8"> |
|
|
|
<meta charset="UTF-8"> |
|
|
|
<title>样式绑定</title> |
|
|
|
<title>样式绑定</title> |
|
|
|
<style> |
|
|
|
<style> |
|
|
|
.basic { |
|
|
|
.basic { |
|
|
|
width: 400px; |
|
|
|
width: 400px; |
|
|
|
height: 100px; |
|
|
|
height: 100px; |
|
|
|
border: 1px solid black; |
|
|
|
border: 1px solid black; |
|
|
|
} |
|
|
|
} |
|
|
|
.happy { |
|
|
|
|
|
|
|
background-color: bisque; |
|
|
|
.happy { |
|
|
|
} |
|
|
|
background-color: bisque; |
|
|
|
.sad { |
|
|
|
} |
|
|
|
background-color: blue; |
|
|
|
|
|
|
|
} |
|
|
|
.sad { |
|
|
|
.normal { |
|
|
|
background-color: blue; |
|
|
|
background-color: orange; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
.test1 { |
|
|
|
.normal { |
|
|
|
background-color: blueviolet; |
|
|
|
background-color: orange; |
|
|
|
} |
|
|
|
} |
|
|
|
.test2 { |
|
|
|
|
|
|
|
border-color: brown; |
|
|
|
.test1 { |
|
|
|
border-width: medium; |
|
|
|
background-color: blueviolet; |
|
|
|
} |
|
|
|
} |
|
|
|
.test3 { |
|
|
|
|
|
|
|
border-radius: 20px; |
|
|
|
.test2 { |
|
|
|
} |
|
|
|
border-color: brown; |
|
|
|
|
|
|
|
border-width: medium; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.test3 { |
|
|
|
|
|
|
|
border-radius: 20px; |
|
|
|
|
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |
|
|
|
<script type="text/javascript" src="../vue.js"></script> |
|
|
|
<script type="text/javascript" src="../vue.js"></script> |
|
|
|
</head> |
|
|
|
</head> |
|
|
|
<body> |
|
|
|
<body> |
|
|
|
|
|
|
|
|
|
|
|
</body> |
|
|
|
</body> |
|
|
|
<div id="root"> |
|
|
|
<div id="root"> |
|
|
|
<div class="basic" :class="style" @click="changeStyle">{{name}}</div> |
|
|
|
<div class="basic" :class="style" @click="changeStyle">{{name}}</div> |
|
|
|
<div class="basic" :class="classArr" @click="changeStyle">{{name}}</div> |
|
|
|
<div class="basic" :class="classArr">{{name}}</div> |
|
|
|
</div> |
|
|
|
<div class="basic" :class="classObj">{{name}}</div> |
|
|
|
<script type="text/javascript"> |
|
|
|
<div class="basic" :style="styleObj">{{name}}</div> |
|
|
|
|
|
|
|
<div class="basic" :style="styleArr">{{name}}</div> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<script type="text/javascript"> |
|
|
|
Vue.config.productionTip = false |
|
|
|
Vue.config.productionTip = false |
|
|
|
new Vue({ |
|
|
|
const vm = new Vue({ |
|
|
|
el: "#root", |
|
|
|
el: "#root", |
|
|
|
data:{ |
|
|
|
data: { |
|
|
|
name: '测试', |
|
|
|
name: '测试', |
|
|
|
style: "normal", |
|
|
|
style: "normal", |
|
|
|
classArr: ["test1", "test2", "test3"] |
|
|
|
classArr: ["test1", "test2", "test3"], |
|
|
|
}, |
|
|
|
classObj: { |
|
|
|
methods:{ |
|
|
|
test1: true, |
|
|
|
changeStyle(){ |
|
|
|
test2: true |
|
|
|
// this.style = "happy" |
|
|
|
}, |
|
|
|
const arr = ['happy', 'sad', 'normal'] |
|
|
|
styleObj: { |
|
|
|
const index = Math.floor(Math.random()*3) |
|
|
|
fontSize: '40px' |
|
|
|
this.style = arr[index] |
|
|
|
}, |
|
|
|
} |
|
|
|
styleObj2: { |
|
|
|
} |
|
|
|
color: 'red' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
styleArr: [{ |
|
|
|
|
|
|
|
fontSize: '40px' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
color: 'red' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
|
|
changeStyle() { |
|
|
|
|
|
|
|
// this.style = "happy" |
|
|
|
|
|
|
|
const arr = ['happy', 'sad', 'normal'] |
|
|
|
|
|
|
|
const index = Math.floor(Math.random() * 3) |
|
|
|
|
|
|
|
this.style = arr[index] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
</html> |
|
|
|
</html> |