vue样式之style

1.直接写样式

1  <div id="box">
2         <strong :style="{color:'green'}">文字...</strong>
3   </div>

2.以数组的方式显示

<div id="box">
        <strong :style="[c]">文字...</strong>
</div>
new Vue({
el:'#box',
data:{
c:{color:'red'}
},
methods:{
  
}
});
 

3.如果是多个样式,以逗号隔开

new Vue({
        el:'#box',
        data:{
               c:{color:'red'},
               b:{backgroundColor:'blue'}
             },
        methods:{
              }
        });
    };
    
<div id="box">
        <strong :style="[c,b]">文字...</strong>
 </div>

4.利用v-bind直接拿到值

new Vue({
                el:'#box',
                data:{
                    a:{
                        color:'red',
                        backgroundColor:'gray'
                    }
                },
                methods:{
                }
            });
        };
<div id="box">
       <strong :style="a">文字...</strong>
</div>

 

posted @ 2017-09-21 16:25  丸、子  阅读(384)  评论(0)    收藏  举报