【发布时间】:2021-05-14 19:58:13
【问题描述】:
这是一个登录功能 我收到“无法读取未定义的属性 rol”错误:这是我的 vueJs 代码:
methods: {
send: function() {
this.error = null;
this.showLoader = true;
this.$http
.post("/login", new FormData(document.getElementById("LoginUser")), {
reponseType: "json"
})
.then(response =>
{
localStorage.setItem("role", response.data.data.rol);
location.href = "/";
},
fail => {
this.showLoader = false;
this.password = "";
for (let message of fail.data.data.messages) {
this.error = this.$t(
message.message.toLowerCase().replace(/ /g, "_")
);
}
}
);
}
}
我做错了什么?谢谢 我一直在尝试解决这个问题,但我没有成功
【问题讨论】:
-
这意味着您的
response.data没有属性data,因此您正在尝试访问具有undefined值的属性rol。也许您不是要添加第二个.data?登录response.data看看是否符合您的预期。 -
不,我已经尝试过了,它不是
-
你可以像这样使用 if(response.data.data){ localStorage.setItem("role", response.data.data.rol); location.href = "/"; }
-
@SebasCarrillo 记录
response.data显示什么? -
您可以在您的问题中添加此回复吗?
标签: javascript vue.js