03-基础-系统指令-v-bind-绑定 style-对象语法

<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width,initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>Document</title>
</head>

<body>
    <div id='app'>
        <!-- : style 对象 
      {}中的key是style的css属性名font-size的js写法
      {}中的value->data中的数据-->
        <p :style="{color:a,fontSize:b}">内容</p>
        <p :style="obj">啦啦</p>
        <p :style="{color:c,backgroundColor:d}">蓝色的吗</p>
        <p :style="objs">噢噢噢噢</p>
    </div>
    <script src='./vue.js'></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                obj: {
                    color: "blue",
                    fontSize: "10px"
                },
                a: "red",
                b: "30px",
                c: 'yellow',
                d: 'green',
                objs: {
                    fontSize: "50px",
                    color: "#ccc"
                }
            },
            methods: {
            }
        });
    </script>
    -----------------11111111111111---------------------------
    <div id="apps">
        <p :style="obj">哈哈哈哈</p>
        <h1 :style='obj'>aaaa</h1>
    </div>
    <script src='./vue.js'></script>
    <script>
        new Vue({
            el: "#apps",
            data: {
                obj: {
                    color: 'yellow',
                    fontSize: '30px',
                    backgroundColor: 'red'
                }
            }
        })
    </script>

</body>

</html>

posted @ 2019-05-28 21:01  193557749  阅读(144)  评论(0编辑  收藏  举报