在js中
//导入
import Vue from ‘vue’
import axios from ‘axios’
import qs from ‘qs’
//全局注册,使用方法为:this.axiosVue.prototype.axios Vue.prototype.axiosVue.prototype.axios = axios
//添加
Vue.use(axios);
在login.vue中使用
//发送axios请求 例如
var _this = this;
//验证
this.$refs.ruleForm2.validate((valid) => {
if (valid) {
//_this.$router.replace('/table');
this.logining = true;
//NProgress.start();
var loginParams = {name: this.ruleForm2.account, pwd: this.ruleForm2.checkPass};
/*//测试axios
_this.$http.get("/test").then(data=>{
console.debug("ssss")
});*/
//模拟登陆
//发送axios请求
//获取后台响应data信息
_this.$http.post("/user/user/login",loginParams).then(data=>{
this.logining = false;
//NProgress.done();
let {success, message, obj} = data;
var p = data.data;
console.debug(p.success);
//判断为false 则登录成功
if (!p.success) {
this.$message({
message: "账户或密码错误",
type: 'error'
});
} else {
console.debug("uuuuuuuu");
//设置值
obj={"name":"xz"};
//类似于session
sessionStorage.setItem('user', JSON.stringify(obj));
this.$router.push({path: '/table'});
}
})
} else {
console.log('error submit!!');
return false;
}
});
}