强制绑定style属性

Posted liuyang-520

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了强制绑定style属性相关的知识,希望对你有一定的参考价值。

1、案例1

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>强制绑定style属性</title>
</head>

<body>
    <div id="app">
        <!--style="color: blue; font-size: 50px;"-->
        <p :style="{color:‘blue‘,fontSize:myFontSize+‘px‘}">pppppppppppppppppp</p>
        <!--color: red; font-size: 35px;-->
        <p :style="myStyle">pppppppppppppppppp</p>
    </div>
    <script src="../js/vue.js" type="text/javascript"></script>
    <script>
        const vm = new Vue({
            el: "#app",
            data: {
                myFontSize: 50,
                myStyle: {
                    color: "red",
                    fontSize: "35px"
                }
            }
        });
    </script>
</body>

</html>

 

以上是关于强制绑定style属性的主要内容,如果未能解决你的问题,请参考以下文章