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>
    <script src="//static.gzj2001.com/vue/axios.min.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);

                    axios.get("/",{
                        params:{username:this.f.username,password:this.f.password}
                    })
                    .then(function(response){
                        console.log(response);
                    })
                    .catch(function(error){
                        console.log(error);
                    })
                }
            }
        })
    </script>
</body>
</html>