首页 > 其他 > 详细

Vue 双向数据绑定v-model

时间:2019-07-23 15:52:44      阅读:79      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">

<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>
  <script src="./lib/vue-2.4.0.js"></script>
  <style>
    h3{
      color: rgb(75, 230, 14);
      font-weight: normal;
      font-size: 20px;
    }
  </style>
</head>

<body>
  <div id="app">  
    <input type="text" style="width:100%;" v-model="msg">
    <h3>{{ msg }}</h3>

    <input type="text" style="width:100%;" v-model="msg1">
    <h3>{{ msg1 }}</h3>
    <input type="button" value="点击改变data的数据" @click="add">
    <!-- v-bind 只能实现数据的单向绑定,从 M 自动绑定到 V, 无法实现数据的双向绑定  -->
    <!-- <input type="text" v-bind:value="msg" style="width:100%;"> -->

    <!-- 使用  v-model 指令,可以实现 表单元素和 Model 中数据的双向数据绑定 -->
    <!-- 注意: v-model 只能运用在 表单元素中 -->
    <!-- input(radio, text, address, email....)   select    checkbox   textarea   -->
    
  </div>

  <script>
    // 创建 Vue 实例,得到 ViewModel
    var vm = new Vue({
      el: #app,
      data: {
        msg: ‘‘,
        msg1:这里显示的是data里面的数据
      },
      methods: {
        //注意 这里的函数想取得data的数据 前面必须带上this
        add() {
          this.msg1=这里显示的已经修改过的数据
        }
      }
    });
  </script>
</body>

</html>

 

Vue 双向数据绑定v-model

原文:https://www.cnblogs.com/wanguofeng/p/11232091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!