Vueå¦ä¹ 06-----CSSæ ·å¼
程序员文章站
2022-07-04 19:32:49
...
1ãclassæ ·å¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.red {
color: red;
}
.thin {
font-weight: 200;
}
.italic {
font-style: italic;
}
.active {
/* é´è· */
letter-spacing: 0.5em;
}
</style>
</head>
</body>
<div id="app">
<!--
red is not defined
:ä¼å»æ¾vmä¸çåé
-->
<!-- <h1 :class="red">1è¿æ¯ä¸ä¸ªh1</h1> -->
<!--
1ã
vueç»å®classçæ¶åï¼éè¦ç¨å符串çå½¢å¼
-->
<!-- <h1 :class="['red','thin']">2è¿æ¯ä¸ä¸ªh1</h1> -->
<!--
2ã
vueç»å®å¤ä¸ªclassçæ¶åï¼éè¦ç¨å符串ãæ°ç»çå½¢å¼
并ä¸å¯ä»¥ä½¿ç¨ä¸å
表达å¼
-->
<!-- <h1 :class="['red','thin',flag?'active':'']">2è¿æ¯ä¸ä¸ªh1</h1> -->
<!--
3ã
æ°ç»ä¸ä½¿ç¨å¯¹è±¡{é®ï¼å¼}ï¼ä»£æ¿ä¸å
表达å¼ï¼æé«å¯è¯»æ§
-->
<!-- <h1 :class="['red','thin', {'active':flag} ]">2è¿æ¯ä¸ä¸ªh1</h1> -->
<!--
4ã
å¨class使ç¨v-bindç»å®å¯¹è±¡çæ¶åï¼å¯¹è±¡çå±æ§æ¯ç±»åï¼ç±äºå¯¹è±¡çå±æ§å¯å¸¦å¯ä¸å¸¦å¼å·ï¼
æ¤å¤æ²¡å¸¦ï¼å±æ§çå¼æ¯ä¸ä¸ªæ è¯ç¬¦ï¼true为æ¾ç¤ºï¼false为ä¸æ¾ç¤º
-->
<h1 :class="{red:true,thin:true, active:true}">2è¿æ¯ä¸ä¸ªh1</h1>
<!--å°claså±æ§å¨vmä¸å£°æä¸ä¸ï¼å¨classç»å®å³å¯-->
<h3 :class="classObj">è¿æ¯ä¸ä¸ªh1</h3>
</div>
<body>
<script src="./lib/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: {
flag: true,
classObj: { red: true, thin: true, active: true, italic: true }
},
methods: {}
});
</script>
</html>
2ãå èæ ·å¼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<!--对象就æ¯æ åºçé®å¼å¯¹éå-->
<h1 :style="styleObj">è¿äºä¸ä¸ªH1</h1>
<h1 :style="[styleObj,styleObj1]">è¿äºä¸ä¸ªH1</h1>
</div>
</body>
<script src="./lib/vue.js"></script>
<script>
var vm = new Vue({
el: "#app",
data: {
styleObj:{color:'red','font-weight':200},
styleObj1:{'font-style':'italic'}
},
methods: {
}
});
</script>
</html>