Таймер углового набора для определенного элемента - PullRequest
0 голосов
/ 07 апреля 2019

Здесь у меня есть некоторая функция 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 секунд, прежде чем он выполнит последний код?

1 Ответ

0 голосов
/ 07 апреля 2019

Используйте функцию установленного тайм-аута, чтобы сделать задержку на несколько секунд

// 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;
    });
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...