- 安装vue-resource到项目中,找到当前项目
输入:npm install vue-resource --save
- 安装完毕后,在main.js中导入,如下所示:
import VueResource from 'vue-resource'
Vue.use(VueResource)
- 使用如下
/api实在config目录下index.js文件中配置的指向后台url的映射
login: function () {
var _this = this;
// alert(_this.ruleForm.username+_this.ruleForm.password);
_this.$http.post('/api/user/login', {
username: _this.ruleForm.username,
password: _this.ruleForm.password
}
).then(function (response) {
var errorcode = response.body.code;
if (errorcode == "10000") {
_this.$router.push(
{
path: '/index'
});
} else {
// _this.$router.push({ path: '/' });
_this.$router.go(0);
}
})
.catch(function (error) {
console.log(error);
});
}