Vue 带参数axios请求

HTML

<template>
      <div class="lbox">
        <input type="text" placeholder="请输入用户名/手机/邮箱"  v-model="username">
        <input type="password" placeholder="密码" v-model="password">
        <input type="button" value="登录" class="login" @click="going">
      </div>
</template>

data定义变量

data(){
	 return{
  	 username:'',
   	 password:'',
	 }
}

methods 带参数post请求

methods:{
	going(){
		 this.$http({
		     url:'接口',
		      method:'post',
		      data:this.$qs.stringify({
			      username: this.username,
			      password: this.password
			    }),
			   headers: {
		        'Content-Type': 'application/x-www-form-urlencoded'
		     	 }
		      }).then(res=>{
		      this.datas = res.data
		      console.log(this.datas)//打印接收的数据
	     })
	}
}

你可能感兴趣的:(Vue 带参数axios请求)