条件样式
<! DOCTYPE html >
< html lang = " en" > < head> < meta charset = " UTF-8" /> < title> 绑定样式</ title> < script type = " text/javascript" src = " ../js/vue.js" > </ script> < style> .classA { border : 3px solid black; } .classB { background-color : skyblue; } .classC { color : red; } .classD { text-shadow : 2px 2px 3px yellow; } </ style> </ head> < body> < div id = " root" > < h2 class = " classA" :class = " myStyle" > {{title}}</ h2> < h2 class = " classA" :class = " {classC:hasC, classD:hasD}" > {{title}}</ h2> < h2 class = " classA" :class = " hasC ? 'classC' : ''" > {{title}}</ h2> < h2 class = " classA" :class = " [b,c,d]" > {{title}}</ h2> < h2 class = " classA" :class = " [b,c,d]" :style = " {fontSize:size}" > {{title}}</ h2> </ div> < script> new Vue ( { el : "#root" , data : { title : "大家过年好" , myStyle : "classB" , hasC : false , hasD : true , b : "classB" , c : "classC" , d : "classD" , size : "40px" , } , } ) ; </ script> </ body>
</ html>