如果用户尝试关闭选项卡或更改路线,我会尝试发出发布请求。但是我得到一个变量的空值。
detectTabClose() {
let newValues = {
question: this.question_id,
user_id: this.$userId //this is global, from root and is ok
};
window.addEventListener("beforeunload", function(e) {
var confirmationMessage = "o/";
(e || window.event).returnValue = confirmationMessage;
console.log(this.question_id); //I get undefined
axios
.post("/submit/answer", newValues)
.then(() => {
console.log("Post before tab closing");
})
.catch(() => {
console.log("Error on post");
});
return confirmationMessage;
});
},
暮色呼如
相关分类