From 990f1dd296ddebbd023519bcb74b38eaa76a8f05 Mon Sep 17 00:00:00 2001 From: Seedgou Date: Fri, 1 Dec 2023 14:54:59 +0800 Subject: [PATCH] init example pdf without onMounted --- src/views/CanvasScanView.vue | 13 +++++++++---- src/views/MagicaScanView.vue | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/views/CanvasScanView.vue b/src/views/CanvasScanView.vue index e7c254cc..963ec43a 100644 --- a/src/views/CanvasScanView.vue +++ b/src/views/CanvasScanView.vue @@ -36,7 +36,7 @@ import MainContainer from '@/components/MainContainer.vue' import { type ScanConfig, defaultConfig, CanvasScanner } from '@/utils/scan-renderer/canvas-scan' import ScanSettingsCard from '@/components/scan-settings/ScanSettingsCard.vue' import PDFUpload from '@/components/pdf-upload/PDFUpload.vue' -import { ref, computed, onMounted, watch } from 'vue' +import { ref, computed, watch } from 'vue' import PDFURL from '@/assets/examples/pdfs/test.pdf' import BackToIndex from '@/components/buttons/BackToIndex.vue' import { useHead } from '@unhead/vue' @@ -59,11 +59,16 @@ useHead({ const pdf = ref(undefined) -onMounted(async () => { +const initExamplePDF = async () => { const response = await fetch(PDFURL) const blob = await response.blob() - pdf.value = new File([blob], 'example.pdf') -}) + const file = new File([blob], 'example.pdf') + if (!pdf.value) { + pdf.value = file + } +} + +initExamplePDF() const config = ref(defaultConfig) const pdfRenderer = computed(() => { diff --git a/src/views/MagicaScanView.vue b/src/views/MagicaScanView.vue index 042e6b05..12c1114b 100644 --- a/src/views/MagicaScanView.vue +++ b/src/views/MagicaScanView.vue @@ -36,7 +36,7 @@ import MainContainer from '@/components/MainContainer.vue' import { type ScanConfig, defaultConfig, MagicaScanner } from '@/utils/scan-renderer/magica-scan' import ScanSettingsCard from '@/components/scan-settings/ScanSettingsCard.vue' import PDFUpload from '@/components/pdf-upload/PDFUpload.vue' -import { ref, computed, onMounted, watch } from 'vue' +import { ref, computed, watch } from 'vue' import PDFURL from '@/assets/examples/pdfs/test.pdf' import BackToIndex from '@/components/buttons/BackToIndex.vue' import { useHead } from '@unhead/vue' @@ -59,11 +59,16 @@ useHead({ const pdf = ref(undefined) -onMounted(async () => { +const initExamplePDF = async () => { const response = await fetch(PDFURL) const blob = await response.blob() - pdf.value = new File([blob], 'example.pdf') -}) + const file = new File([blob], 'example.pdf') + if (!pdf.value) { + pdf.value = file + } +} + +initExamplePDF() const config = ref(defaultConfig) const pdfRenderer = computed(() => {