Vue教程(九) v-bind:class动态绑定
程序员文章站
2022-05-15 17:44:40
...
Vue教程(九) v-bind:class动态绑定
v-bind:class 动态绑定样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>09_bind_css_style</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
.active {
color: blue;
font-size: 18px;
}
</style>
</head>
<body>
<h3>模板语法</h3>
<div id="app">
<span v-on:click="btnClick" v-bind:class="{'active':isActive}">{{message}}</span><br/>
<span :style="getStyles()">{{message}}</span>
</div>
<script>
const app = new Vue({
el: "#app",
data: {
message: "hello vue!",
isActive: true,
fontSize:'24px',
backgroundColor:'red'
},
methods: {
btnClick: function () {
this.isActive = !this.isActive
},
getStyles:function (){
return {fontSize:this.fontSize,backgroundColor:this.backgroundColor}
}
}
});
</script>
</body>
</html>
– 以上为《Vue教程(九) v-bind:class动态绑定》,如有不当之处请指出,我后续逐步完善更正,大家共同提高。谢谢大家对我的关注。
——厚积薄发(yuanxw)
下一篇: vue指令