• 双向数据绑定


    <!doctype html>
    <html>
     <head>
      <meta charset="UTF-8">
      <title>经典的双向数据绑定</title>
        <script src="js/vue.js"></script>
     </head>
     <body>
      <div id="container">
        <button @click="modifyMsg">修改msg</button>
    <!-- 方向1:将定义好的数据绑定到试图  
    实现方式:双花括号  
    常见指令:v-for v-if v-show …… -->
    <!--  方向2:将视图中用户操作的结果  绑定到指定的数据   (多数指表单控件  input/textarea/select)
        实现方式: v-model
    -->
            <p>{{msg}}</p>
            <input type="text" v-model="userAddress">
            <p>{{"用户修改的数据:"+userAddress}}</p>
            <hr>
            <h2>v-model.number</h2>
            <input type="text" v-model.number="n">
            <br>
            <input type="text" v-model.number="m">
            <br>
            <button @click="getNum">求和</button>
            <span>{{num}}</span>
            <hr>
            <h2>v-model.trim</h2>
            <h5>没有过滤首尾空格时:</h5>
            <input type="text" v-model="myInput">
            <span>{{myInput.length}}</span>
            <h5>过滤首尾空格时:</h5>
            <input type="text" v-model.trim="myInput">
            <span>{{myInput.length}}</span>
            <h2>v-moddel.lazy</h2>
            <h5>input失去焦点时才会输出myMsg</h5>
            <input type="text" v-model.lazy="myMsg">
            <span>{{myMsg}}</span>
        </div>
        <script>
            new Vue({
                el:"#container",
                data:{
                    msg:"Hello VueJs",
                    userAddress:"",
                    n:0,
                    m:0,
                    num:0,
                    myInput:0,
                    myMsg:""
                },
                methods:{
                    modifyMsg:function(){
                        this.msg = "Hello Model"
                    },
                    getNum:function(){
                        this.num = this.n+this.m;
                    }
                }
            })
        </script>
     </body>
    </html>
  • 相关阅读:
    ElasticSearch 2 (1)
    Vagrant (2) —— 基本安装与配置(下)
    Vagrant (1) —— 基本安装与配置(上)
    Vagrant (3) —— 复制/备份Vagrant Box
    vue中$forceUpdate的使用
    vue+ElementUi 选择框选中之后翻页进行状态保持及默认选中
    loonflow 工单系统
    一些后端知识
    前端学习计划
    async/await函数的执行顺序的理解
  • 原文地址:https://www.cnblogs.com/wangruifang/p/7765180.html
Copyright © 2020-2023  润新知