这里我有一些jspdf函数
public captureScreen() {
// Start from here
this.loading = true;
const data = document.getElementById('convert');
html2canvas(data).then(canvas => {
const imgWidth = 208;
const pageHeight = 295;
const imgHeight = canvas.height * imgWidth / canvas.width;
const heightLeft = imgHeight;
const contentDataURL = canvas.toDataURL('image/png');
const pdf = new jspdf('p', 'mm', 'a4');
const position = 0;
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
pdf.save('Test.pdf');
// Until here
this.loading = false;
});
}我想让这个函数运行一秒钟,直到它再次将this.loading返回为false。我怎样才能让一个计时器在执行最后一段代码之前设置2-3秒?
发布于 2019-04-07 11:29:27
使用set timeout函数延迟几秒钟
// When calling function
this.loading = true;
setTimeout(function() { captureScreen(); }, 3000);
public captureScreen() {
const data = document.getElementById('convert');
html2canvas(data).then(canvas => {
const imgWidth = 208;
const pageHeight = 295;
const imgHeight = canvas.height * imgWidth / canvas.width;
const heightLeft = imgHeight;
const contentDataURL = canvas.toDataURL('image/png');
const pdf = new jspdf('p', 'mm', 'a4');
const position = 0;
pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
pdf.save('Test.pdf');
// Until here
this.loading = false;
});
}https://stackoverflow.com/questions/55555118
复制相似问题