javascript - this.function 不是函数,但我可以在其他方法上访问此方法
问题描述
我在getTestContent函数中执行submitMyAnswer时遇到问题。我认为这与 clearIntervals 有关,但事实并非如此。我尝试将“submitMyAnswer”函数的全部内容添加到我的主函数中,但它给了我一个错误。我应该怎么办?我应该尝试“返回”该方法吗?cannot read property 'dispatch' of undefined
//other method is called submitMyAnswer
getTestContent() {
this.gotEm2 = true;
this.gotEm = false;
localStorage.getItem("savedId");
axios
.get("https://www.derptech.site/MyComposer/", {
params: {
id: 8,
testToken: this.selectedTest,
},
})
.then((res) => {
for (var l = 0; l < res.data.length; l++) {
this.quizTime = res.data[l].Duration;
this.testContentData.push({
testId: res.data[l].TestId,
daimage: res.data[l].DaImage,
question: res.data[l].Question,
});
}
var totalSeconds;
if (this.quizTime != 0) {
if (localStorage.getItem("totalSeconds")) {
totalSeconds = localStorage.getItem("totalSeconds");
} else {
totalSeconds = this.quizTime;
}
var minutesLabel = document.getElementById("minutes");
var secondsLabel = document.getElementById("seconds");
var startThisTime = setInterval(setTime, 1000);
//setInterval(setTime, 1000);
function setTime() {
--totalSeconds;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
localStorage.setItem("totalSeconds", totalSeconds);
if (totalSeconds <= 0) {
clearInterval(startThisTime);
this.submitMyAnswer();
}
}
function pad(val) {
var valString = val + "";
if (valString.length < 2) {
return "0" + valString;
} else {
return valString;
}
}
window.addEventListener("beforeunload", function(e) {
e.preventDefault();
s;
e.returnValue = "";
});
}
});
},
解决方案
推荐阅读
- wordpress - 如何在 woocommerce 中检查订单备注的类型
- mysql - Python查询2或参数中的Mysql
- c# - 从 vue 引导按钮调用方法会停止页面渲染
- reactjs - Not able to handle change/click on inner elements (displyed using onRenderField) of ChoiceGroup in office-ui-fabric-react
- java - 我们可以仅在加载彼此之后添加一个 Maven 依赖项吗?
- bash - 有没有办法在这种情况下只需要一个回声?
- reactjs - 反应 js + laravel 部署
- css - 对角线 SVG 行程
- c++ - CublasLt cublasLtMatmulAlgoGetHeuristic 为行主矩阵返回 CUBLAS_STATUS_INVALID_VALUE
- python - Pony orm 连接池