<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>多種方式使用VUE控制style樣式屬性</title> <script src="vue.js"></script> </head> <body> <!--使用變量或是字符串定義樣式屬性--> <div id="lantian"> <h1 :style="{color:'red',fontSize:size+'px'}">美麗中國</h1> <h1 :style="{color:red,fontSize:'50px'}">美麗中國</h1> <hr /> <input type="number" v-model="size" /> <hr /> <!--object變量定義--> <h2 :style="style">中國美麗</h2> <!--數組定義--> <h2 :style="[ltcms]">中國美麗</h2> </div> <script> var app=new Vue({ el:'#lantian', data:{ red:'green', size:20, style:{ color:'blue', fontSize:'100px' }, ltcms:{ color:'#188eee', backgroundColor:'#999' } } }); </script> </body> </html>