zoukankan      html  css  js  c++  java
  • vue v-model属性

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="utf-8">
     5         <title></title>
     6         <script src="../vue.js" type="text/javascript" charset="utf-8"></script>
     7     </head>
     8     <body>
     9         <div id="app">
    10             <input type="text" v-model="n1">
    11             <select v-model="opt">
    12                 <option value="+">+</option>
    13                 <option value="-">-</option>
    14                 <option value="*">*</option>
    15                 <option value="/">/</option>
    16             </select>
    17             <input type="text" v-model="n2">
    18             <input type="button" value="=" v-on:click="calca">
    19             <input type="text" v-model="result">
    20         </div>
    21     </body>
    22     <script type="text/javascript">
    23         var vm = new Vue({
    24             el: "#app",
    25             data: {
    26                 n1: 0,
    27                 n2: 0,
    28                 result: 0,
    29                 opt: "+",
    30             },
    31             methods: {
    32                 calca: function() {
    33                     // switch (this.opt) {
    34                     //     case "+":
    35                     //         this.result = parseInt(this.n1) + parseInt(this.n2);
    36                     //         break;
    37                     //     case "-":
    38                     //         this.result = parseInt(this.n1) - parseInt(this.n2);
    39                     //         break;
    40                     //     case "*":
    41                     //         this.result = parseInt(this.n1) * parseInt(this.n2);
    42                     //         break;
    43                     //     case "/":
    44                     //         this.result = parseInt(this.n1) / parseInt(this.n2);
    45                     //         break;
    46                     // }
    47                     this.result = eval("parseInt(this.n1) " + this.opt + " parseInt(this.n2)");
    48                 }
    49             }
    50         });
    51     </script>
    52 </html>

    注意:v-model只能用于表单元素

  • 相关阅读:
    链表的Java实现
    java知识点
    java知识点
    Android基础知识总结
    Android基础知识总结
    路由知识之ip route 命令中的疑惑
    Integer与int的种种比较
    求二叉树的宽度C语言版
    求二叉树的宽度C语言版
    二叉树的建立与递归遍历C语言版
  • 原文地址:https://www.cnblogs.com/yanghaoyu0624/p/11490402.html
Copyright © 2011-2022 走看看