我在 Vue.js 中有一个函数,它将数据发送到后端以让用户登录。但是,如果用户不存在,它会返回 401 未经授权。这对我来说没问题,问题是它似乎总是登录到控制台。我已经知道我可以处理它,但它总是记录到控制台。有没有办法阻止 Web 控制台记录未经授权的 401?
我的功能
this.$store
.dispatch("userLogin", {
username: this.username,
password: this.password,
})
.then((response) => {
switch (response.status) {
case 401:
//I know unauthorized attempt can be handled here.
break;
}
this.$router.push({ name: "Admin" });
})
.catch(function (error) {
console.log(error.response.data);
});
}
我想阻止它被记录。
最佳答案
你不能这么做。这与尝试阻止请求显示在 Chrome 的“网络”选项卡中相同。它是由浏览器实现的,网站无法控制它。
关于javascript - 有没有办法阻止 401 未经授权登录控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70656202/