其他分享
首页 > 其他分享> > vue10-3 v-bind绑定style用法

vue10-3 v-bind绑定style用法

作者:互联网

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-bind:class</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <style>
        .basic{
            width: 100px;
            height: 100px;
            border: 3px solid black;
        }
    </style>
</head>
<body>
    <div id="root"> 
         <!-- 绑定style样式--对象写法 -->
        <div class="basic" :style="styleObj">hah</div><br/>

        <!-- 绑定style样式--methods中的方法写法 -->
        <div class="basic" :style="getColor()">hah</div>
    </div>
    <script type="text/javascript">
        new Vue({
            el: '#root', 
            data() {
                return {
                    name: 'leaf',
                    styleObj:{
                        fontSize: '40px',
                        color: 'red',
                        backgroundColor: 'orange'
                    }
                }
            },
            methods: {
                getColor(){
                    return {color: 'yellow'}
                }
            },
        })
    </script>    
</body>
</html>

 

标签:hah,el,style,return,vue10,color,bind,100px
来源: https://www.cnblogs.com/leafchen/p/16478046.html