当前位置: 移动技术网 > IT编程>脚本编程>vue.js > 详解Vue.js之视图和数据的双向绑定(v-model)

详解Vue.js之视图和数据的双向绑定(v-model)

2017年12月12日  | 移动技术网IT编程  | 我要评论

1、使用v-model指令,使得视图和数据实现双向绑定。v-model主要用在表单的input输入框,完成视图和数据的双向绑定。

2、javascript代码

<script type="text/javascript" src="../js/vue-1.0.21.js"></script> 
 
    <script type="text/javascript"> 
      window.onload = function() { 
         vm = new vue({ 
          el: '#app', 
          data: { 
            message: 'hello world', 
          } 
 
        }); 
      } 
    </script> 

3、html的页面代码

<div id="app" class="container"> 
      <input type="text" v-model='message'/> <input type="text" v-model='message'/> 
      <br /> 
      {{message}} 
    </div> 

4、完整的代码

<!doctype html> 
<html> 
 
  <head> 
    <meta charset="utf-8"> 
    <title></title> 
    <link rel="stylesheet" href="../css/bootstrap.min.css" rel="external nofollow" /> 
    <style type="text/css"> 
      .container{ 
        margin-top: 20px; 
      } 
    </style> 
    <script type="text/javascript" src="../js/vue-1.0.21.js"></script> 
    <script type="text/javascript" src="../js/jquery.min.js"></script> 
    <script type="text/javascript"> 
      $().ready(function() { 
        var vm = new vue({ 
          el: '#app', 
          data: { 
            message: "hello world ! " 
          } 
        }); 
      }); 
    </script> 
  </head> 
 
  <body> 
 
    <div id="app" class="container"> 
      <input type="text" v-model='message'/> <input type="text" v-model='message'/> 
      <br /> 
      {{message}} 
    </div> 
 
  </body> 
 
</html> 

5、效果演示           

 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网