get/post使用

2018/12/19 21:42
阅读数 56
// 方法一 post
this.axios({
  url : url,
  method: 'POST',
 
  // data : $.param({username:this.username,password:this.password}),
  // //$.param()的含义:序列化对象,返回字符串 用form表单传递数据
  // headers: {'BsmAjaxHeader': true}
  dataType:JSON,
  data:{username:this.username,password:this.password} //json格式
}).then(res=>{
console.log(res)
if(res.data.success == true){
alert(res.data.message)
this.$router.push({path: '/details'});
}else{
alert(res.data.message)
}
})

 

 
// 方法二 get
// this.axios.get(url,{params:{username:this.username,password:this.password}}).then(res=>{
// this.axios.get(url,{params:{"username":this.username,"password":this.password}}).then(res=>{
// // console.log(this.username)
// // console.log(this.password)
// console.log(res.data)
// if(res.data == 0){
// this.$router.push({path: '/index'});
// }else{
// alert("登录失败")
// }
// })
   
 
// 方法三 json格式传递
// var obj = {username:this.username,password:this.password} /* url传递参数*/
// this.axios.post(url,obj).then((res)=>{
// // this.axios.post(url,this.qs.stringify(obj)).then((res)=>{ url传递参数后端对象格式接收
// console.log(res)
// if(res.data == 0){
// this.$router.push({path: '/index'});
// }else{
// alert("登录失败")
// }
// })

  

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部