Talking about the uncommon instructions and their functions in vue

1. Vue instructions that are not commonly used but can be used

v-clock: Set the default style of the element vue before loading

The v-once setting element can only be rendered once by vue

v-pre setting elements are not rendered by vue

 Two: These three instructions and their application

v-clock: Set the default style of the element vue before loading

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 导包 -->
    <script src="./vue.js"></script>

    <style>
        /* 属性选择器: [属性名]{ css样式 } */
        [v-cloak]{
            color: red;
            background-color: skyblue;
        }
    </style>
</head>

<body>

    <!-- HTML结构 -->
    <div id="app">
        <p v-cloak>{
   
   { msg }}</p>
    </div>
 <script>
        /* 创建vue实例 */
        let app = new Vue({
            //el:挂载点
            el: '#app',
            //data: 要渲染的数据
            data: {
                msg: '我是坤坤!',
            }
        })
    </script>
</body>
</html>

The v-once setting element can only be rendered once by vue

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 导包 -->
    <script src="./vue.js"></script>
</head>

<body>

    <!-- HTML结构 -->
    <div id="app">
        <p>我没有使用v-once,我的名字叫:{
   
   { msg }}</p>
        <button @click="doClick">点我改数据</button>
        <p v-once>我使用了v-once,我的名字叫:{
   
   { msg }}</p>
    </div>
 <script>
        /* 创建vue实例 */
        let app = new Vue({
            //el:挂载点
            el: '#app',
            //data: 要渲染的数据
            data: {
                msg: '我是坤坤!',
            },
            methods: {
                doClick:function(){
                    this.msg = '我是aikun!'
                }
            },
        })
    </script>
</body>
</html>

 

v-pre setting elements are not rendered by vue

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 导包 -->
    <script src="./vue.js"></script>
</head>

<body>

    <!-- HTML结构 -->
    <div id="app">
        <p>我没有使用v-pre,我的名字叫:{
   
   { msg }}</p>
        <button @click="doClick">点我改数据</button>
        <p v-pre>我使用了v-pre,我的名字叫:{
   
   { msg }}</p>
    </div>
   
    <script>
        /* 创建vue实例 */
        let app = new Vue({
            //el:挂载点
            el: '#app',
            //data: 要渲染的数据
            data: {
                msg: '我是坤坤!',
            },
            methods: {
                doClick:function(){
                    this.msg = '我是aikun!'
                }
            },
        })
    </script>
</body>
</html>

These instructions are not commonly used, but it is very convenient to use their operations in certain scenarios 

 

Guess you like

Origin blog.csdn.net/weixin_71171795/article/details/128501370