美文网首页
Vue-双向数据绑定

Vue-双向数据绑定

作者: linlu_home | 来源:发表于2019-02-22 17:57 被阅读0次
    <DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Vue.js</title>
        <link rel="stylesheet" href="style2.css">
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    </head>
    <body>  
        <div id="vue-app">
            <h1>双向数据绑定input/select/textarea</h1>
            <label>姓名:</label>
            <input type="text" ref="name" v-on:keyup="logName">
            <span>{{ name }}</span>
            <label>年龄:</label>
            <input type="text" ref="age" v-on:keyup="logAge">
            <span>{{ age }}</span>
        </div>
    
        <script src="app4.js"></script>
    </body>
    </html>
    

    js:

    new Vue({
        el:"#vue-app",
        data:{
            name:"zouzou",
            age:30,
        },
        methods:{
            logName: function(){
                this.name = this.$refs.name.value;
            },
            logAge: function(){
                this.age = this.$refs.age.value;
            }
    
        }   
    });
    

    或者:

    <div id="vue-app">
            <h1>双向数据绑定input/select/textarea</h1>
            <label>姓名:</label>
            <input type="text" v-model="name">
            <span>{{ name }}</span>
            <label>年龄:</label>
            <input type="text"  v-model="age">
            <span>{{ age }}</span>
        </div>
    

    相关文章

      网友评论

          本文标题:Vue-双向数据绑定

          本文链接:https://www.haomeiwen.com/subject/mltyyqtx.html