get请求
- 需要请求的页面
- 需要提交的数据/从后台请求回来的数据
- 处理响应的数据
- 多用于请求页面数据例如图片,文字等等
post请求
- 请求的url
- 需要提交的数据
axios.post('/api/users',{
userName:this.username,
userPassword:this.userpwd
}).then((respoonse) =>{
var users = respoonse.data.result.list
console.log(users);
console.log(this.userpwd);
console.log(users.userPassword);
if (this.username==users) {
localStorage.setItem('user',users)
var user = localStorage.getItem('user')
this.$store.commit('getloginuser',user)
window.location.href='http://localhost:8080/#/'
} else if (users==false) {
user.style.border='1px solid #ff6700'
this.errorbol=true
}
})
- 后端需要链接数据库,接受前端发送的数据,并且处理之后返回指令
router.post('/', function(req, res, next) {
var param = {
userName:req.body.userName,
userPwd:req.body.userPwd
}
console.log(param);
User.findOne(param,function (err,doc) {
if (err) {
res.json({
status:1,
msg:err.message,
});
}else {
console.log(doc);
if (doc==null){
res.json({
status:0,
msg:'',
result:{
list:false
}
})
} else {
res.json({
status:0,
msg:'',
result:{
list:doc.userName
}
})
}
}
})
});