4vue学习_v-once和v-html和v-pre和v-cloak

1、如果不想要,交互式修改则,备注v-once

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title-hellovuejs</title>
</head>
<body>
    <div id ="app">
        <h2>{{message}}</h2>
        <h2 v-once>{{message}}</h2>       

    </div>
    <script src="../js/vue.js"></script>
    <script>
        //let(变量) /const(常亮)
        const chen1 = new Vue({
            el: '#app',  //用于挂载要管理的元素
            data:{//定义数据
                message: '数据显示'      
            },
        })
    </script>
</body>

标注后的不响应修改

2、v-html处理html格式的内容

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title-hellovuejs</title>
</head>
<body>
    <div id ="app">
        <h2>{{url}}</h2>
        <h2 v-html="url"></h2>       

    </div>
    <script src="../js/vue.js"></script>
    <script>
        //let(变量) /const(常亮)
        const chen1 = new Vue({
            el: '#app',  //用于挂载要管理的元素
            data:{//定义数据
                message: '数据显示',
                url:'<a href="http://www.baidu.com">百度一下</a>'      
            },
        })
    </script>
</body>

 显示结果如下

3、v-pre内购原封不动显示你要显示的

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title-hellovuejs</title>
</head>
<body>
    <div id ="app">
        <h2>{{message}}</h2>
        <h2 v-pre>{{message}}</h2>       

    </div>
    <script src="../js/vue.js"></script>
    <script>
        //let(变量) /const(常亮)
        const chen1 = new Vue({
            el: '#app',  //用于挂载要管理的元素
            data:{//定义数据
                message: '数据显示',  
            },
        })
    </script>
</body>

 显示结果如下

4、v-cloak(斗篷)初始化不显示,遮挡下(比如js运行卡住时,不让用户看到变量),更友好些。 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title-hellovuejs</title>
    <style>
        [v-cloak]{
            display: none;
        }
    </style>
</head>
<body>
    <div id ="app" v-cloak>
        <h2>{{message}}</h2>
    </div>
    <script src="../js/vue.js"></script>
    <script>
        //let(变量) /const(常亮)
        const chen1 = new Vue({
            el: '#app',  //用于挂载要管理的元素
            data:{//定义数据
                message: '数据显示',  
            },
        })
    </script>
</body>

看到效果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值