vue中的指令:

2018-09-24  本文已影响0人  张鑫冲
1,v-html: 操作元素中的HTML标签
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
   <div id='app'>
       <input type="text" v-model='msg'>
       <p v-html='msg'>{{msg}}</p>
      
       
   </div>
    <script src="../js/vue.js"></script>
    <script>
       new Vue({
           el:'#app',
           data:{
               msg:'hello'
           }
       })
    </script>
</body>
</html>
2,v-text: 操作元素中的纯文本
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
   <div id='app'>
       <input type="text" v-model='msg'>    
       <h3 v-text='msg'>{{msg}}</h3>     
   </div>
    <script src="../js/vue.js"></script>
    <script>
       new Vue({
           el:'#app',
           data:{
               msg:'hello'
           }
       })
    </script>
</body>
</html>
3,v-once:只绑定一次
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
   <div id='app'>
       <input type="text" v-model='msg'>            
       <a href="" v-once>{{msg}}</a>       
   </div>
    <script src="../js/vue.js"></script>
    <script>
       new Vue({
           el:'#app',
           data:{
               msg:'hello'
           }
       })
    </script>
</body>
</html>
4,v-pre:原样输出
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
   <div id='app'>
       <input type="text" v-model='msg'>   
       <h1 v-pre>{{msg}}</h1>       
   </div>
    <script src="../js/vue.js"></script>
    <script>
       new Vue({
           el:'#app',
           data:{
               msg:'hello'
           }
       })
    </script>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读