<body>
<div id="app">
<!-- 對象是無序鍵值對的集合 -->
<h1 :style="styleObj1">這是一個h1</h1>
<h1 :style="[styleObj1, styleObj2]">這是一個h1</h1>
</div>
<script>
var vm = new Vue({
el: '#app',
data: {
styleObj1: { color: 'red' , 'font-weight': 200 },
styleObj2: { 'font-style': 'italic' },
},
methods: {
}
})
</script>
</body>
使用v-bind
綁定style
,添加樣式
- 使用對象:對象是無序鍵值對的集合
- 使用對象數組:數組內可以包含多個對象