Within the operating line style - in the style object syntax // operating line - array syntax

Operating inline style - object syntax

<!DOCTYPE html>
<html lang="en">

<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">
        <!-- 基本用法 -->
        <h1 v-bind:style="{color: 'pink', fontSize: '18px'}">{{name}}</h1>
        <!-- 使用 data 选项中样式 -->
        <h1 v-bind:style="style1">{{name}}</h1>
        <!-- 样式切换 -->
        <h1 v-bind:style="isTrue ? style1 : style2">{{name}}</h1>
    </div>

    <script src="./vue.js"></script>
    <script>

        new Vue({
            data: {
                name: '赵胤祯',
                isTrue: true,
                style1: {
                    color: 'red',
                    fontSize: '18px'
                },
                style2: {
                    color: 'green',
                    fontSize: '18px'
                }
            }
        }).$mount('#app')

    </script>
</body>

</html>

Operating inline styles - array syntax

<!DOCTYPE html>
<html lang="en">

<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">
        <!-- 基本用法 -->
        <h1 v-bind:style="[{color: 'white', fontSize: '18px'}, {backgroundColor: 'green'}]">{{name}}</h1>
        <!-- 使用 data 选项中样式 -->
        <h1 v-bind:style="[style1, style2]">{{name}}</h1>
        <!-- 样式切换 -->
        <h1 v-bind:style="[isTrue ? style1 : style2]">{{name}}</h1>
    </div>

    <script src="./vue.js"></script>
    <script>

        new Vue({
            data: {
                name: '赵胤祯',
                isTrue: true,
                style1: {
                    color: 'red',
                    fontSize: '18px'
                },
                style2: {
                    color: 'green',
                    fontSize: '18px'
                }
            }
        }).$mount('#app')

    </script>
</body>

</html>

Published 151 original articles · won praise 1 · views 1870

Guess you like

Origin blog.csdn.net/qq_45802159/article/details/103816698