Vue 使用v-bind:style 绑定样式

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">好好学习</div>
            <div v-bind:style="styleObject">天天向上</div>
        </div>
    </body>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                activeColor: 'blue',
                fontSize: 30,
                styleObject: {
                    color: 'green',
                    fontSize: '50px'
                }
            }
        })
    </script>
</html>

效果:

 

posted @ 2019-04-10 11:55  随★风  阅读(13506)  评论(0编辑  收藏  举报