Home  >  Article  >  Web Front-end  >  How to set style in vue

How to set style in vue

青灯夜游
青灯夜游Original
2021-10-27 15:15:3515315browse

Method: 1. Use the style attribute of the tag to add an inline style; 2. Use the "v-bind" command to set the style style through binding; 3. Set the vue attribute to the style with the syntax ":style ="obj"" or ":style="[obj,obj1...]"".

How to set style in vue

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

Vue sets style

1. Add inline style directly

2. Set style through binding

3. Set vue's attributes as styles (vue attributes can be multiple)

<div id="box">
            <!--直接添加样式-->
            <p style="background-color: blue;">sssss</p>
            <!--绑定样式-->
            <p v-bind:style="&#39;background-color: red;&#39;">sssss</p>
            <!--将vue中的属性作为样式设置-->
            <p :style="obj">sssss</p>
            <!--将多个属性作为样式设置-->
            <p :style="[obj,obj1]">sssss</p>
        </div>
        <script type="text/javascript">
            var vm=new Vue({
                el:"#box",
                data:{
                    obj:{
                        backgroundColor:"gold"
                    },
                    obj1:{
                        fontSize: "30px"
                    }
                },
            });
        </script>

Related recommendations: "vue.js Tutorial"

The above is the detailed content of How to set style in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn