1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <div id="example"> <!-- 바인딩 방법 1 --> <button id="a" v-bind:style="style1" @mouseover.stop="overEvent" @mouseout.stop="outEvent">테스트</button> <!-- 바인딩 방법 2 --> <div :style="{ backgroundColor: style2.bc, width:style2.w+'px', height:style2.h+'px' }"></div> <!-- 복수 스타일 바인딩 --> <div :style="[myColor, myLayout]"></div> </div>
<script> var vm = new Vue({ el : "#example", data : { style1 : { backgroundColor:"aqua", border:'solid 1px gray', with:'100px', textAlign:'center' }, style2 : { bc:"yellow", bd:'solid 1px gray', w:200, h:100 }, myColor : { backgroundColor: 'purple', color: 'yellow' }, myLayout : { width: '150px', height: '80px' } }, methods : { overEvent : function(e) { this.style1.backgroundColor = "purple"; this.style1.color = "yellow"; }, outEvent : function(e) { this.style1.backgroundColor = "aqua"; this.style1.color = "black"; } } }) </script>
|