image.png

代码

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js-表单-实战-获取要提交的数据</title>
    <script src="//static.gzj2001.com/vue/vue.js"></script>
</head>
<body>
    <div id="app">
        <form @submit.prevent="tijiao">
            <input type="text" name="username" id="" v-model="f.username">
            <input type="password" name="password" id="" v-model="f.password">
           <input type="submit" value="提交">
        </form>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                f:{}
            },
            methods:{
                tijiao:function(){
                    console.log(this.f);
                    console.log(this.f.username);
                    console.log(this.f.password);
                }
            }
        })
    </script>
</body>
</html>