-
[上海|荣耀师兄]JS-左昌杰0
安装axios
在main.js 里初始化$http
import axios from "axios";
Vue.prototype.$http=axios;
this.$http({
method: "POST", //定义POST请求
url: "/carrots-admin-ajax/a/login", //请求地址
params: { //params可以把$scope的对象序列化成键值对形式
name: this.user,
pwd: this.password,
}
}).then(response => { //发起请求成功
console.log(response);
// console.log(response.data)
// console.log(response.data.code)
if (response.data.code == "-5003") {
this.hint = response.data.message; //提示用户名错误
} else if (response.data.code == "-5004") {
this.hint = response.data.message; //提示密码错误
} else if (response.data.code == "0") {
// console.log(response.data.code)
this.hint = "登录成功"; //提示登录成功
let username = response.data.data.manager.name;
// console.log(username);
localStorage.setItem("username", JSON.stringify(username));
// this.$router.push({ path: "/Home"});
}
}, function (response) { //发起请求失败
// console.log(response);
location.href = "404"; //跳转到404
})
编辑于2019-01-25
- 去第 页