Axios跨域实例


//创建axios实例
var instance = axios.create({
baseURL : "http://localhost:8080",
withCredentials : true
});

 

instance.post("/user/login","username="+axios_username+"&password="+axios_password).then(function (response) {
let user = response.data;
if(typeof user == "object" && user.id != null){
alert("登录成功",JSON.stringify(user));
localStorage.setItem("session_user",JSON.stringify(user));
}else{
alert("账号密码错误");
}
}).catch(function (error) {
alert("网路错误");
});

 

instance.get("/user/getOne/"+axios_id).then(function(response){
let user = response.data;
console.log("user=",user);
if(typeof user == "object" && user.id != null){
data.user = JSON.stringify(user);
}else{
alert("没有该用户");
}

}).catch(function(error){
alert("您没有登录");
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM