vue表单示例

pythonclass 2020-05-09

v-model 指令,用于在表单类元素上双向绑定数据
 
用@input 来替代 v-model 示例
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        姓名:<textarea type="text"  @input="handle" cols=20 rows=3></textarea><br/>
        <span>输入的姓名是:{{name}}</span>
    </div>
    <script>
        var v=new Vue({
            el:"#app",
            data:{
                name:""
            },
            methods:{
                handle:function(e){
                    this.name=e.target.value;
                }
            }
        });
    </script>
</body>
</html>
 
 

相关推荐

lyjava / 0评论 2020-07-30