vue-resource

The plugin for Vue.js provides services for making web requests and handle responses using a XMLHttpRequest or JSONP

以上是官方解释:vue-resource 是一个为vue 提供web请求与处理响应的类jQuery Ajax的插件且支持json对象与XMLHttpRequest对象

话不多说,进入正题

HTML部分

<div class="page_bd">
        <div class="weui-cells">
           <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" v-model="student.userName" type="text" placeholder="姓名">
                </div>
            </div>
        </div>

        <div class="weui-cells">
           <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" v-model="student.phoneCode"  placeholder="手机">
                </div>
            </div>
        </div>
</div>
        

js部分

<script>
export default {
    data:{
        return {
            student:{
                userName:"",
                phoneCode:""
            }
        }
    },
    methods: {
        doSubmit(){
           
            var formData = JSON.stringify(this.student); // 这里才是你的表单数据
            this.$http.post(url,formData).then(function(data){
                if(data.json().state=="success"){
                    setTimeout(function () {
                        console.log("success");  
                    }, 2000);       
                }
            
            }).catch(function(){
              console.log("服务器异常!");
            });
            

        }

    }
}
</script>

欢迎指正 499260459@qq .com

so easy , that's end


程序猿二十七
153 声望3 粉丝