内置指令-cloak // 内置指令-once // 内置指令-pre

内置指令-cloak

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

<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>
    <style>
        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>

    <div id="app">
        <div v-cloak>
            <h1>{{message}}</h1>
            <h1>{{message}}</h1>
            <h1>{{message}}</h1>
        </div>
    </div>

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

        new Vue({
            el: '#app',
            data: {
                message: 'Hello World'
            }
        })
    </script>
</body>

</html>

内置指令-once

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

<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">
        <!-- 默认情况下,message 的值发生变化时,界面也会随着改变。
            使用 v-once 指令之后,元素或组件只会被编译一次,再次渲染界面时,
            元素或组件及其所有后代都会被作为静态内容跳过。这样做可以优化界面的渲染速度。 -->

        <template v-once>
            <h1>{{message}}</h1>
            <h1>{{message}}</h1>
        </template>
        
        <h1>{{message}}</h1>
        <h1>{{message}}</h1>
    </div>
## 标题
    <script src="./vue.js"></script>
    <script>

        new Vue({
            el: '#app',
            data: {
                message: 'Hello World'
            }
        })
    </script>
</body>

</html>

内置指令-pre

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

<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">
        <!-- 当你的页面有大量的静态内容时,我们可以使用 v-pre 跳过这些内容的编译,这样可以加快编译速度。 -->
        <div v-pre>
            <h1>你好,世界!</h1>
            <h1>你好,世界!</h1>
            <h1>{{message}}</h1>
        </div>
        
        <h1>{{message}}</h1>
        <h1>{{message}}</h1>
    </div>

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

        new Vue({
            el: '#app',
            data: {
                message: 'Hello World'
            }
        })
    </script>
</body>

</html>
发布了151 篇原创文章 · 获赞 1 · 访问量 1853

猜你喜欢

转载自blog.csdn.net/qq_45802159/article/details/103829524