diff --git a/demo/App.vue b/demo/App.vue index 0e9d0d3..5ca5b5b 100644 --- a/demo/App.vue +++ b/demo/App.vue @@ -7,6 +7,7 @@ +
+ + @@ -50,6 +53,41 @@ export default { } }, methods: { + handleTestFetch() { + fetch('http://localhost:3000/pdf', { + headers: { + 'Content-Type': 'application/pdf', + }, + }).then(res => { + const reader = res.body.getReader() + const stream = new ReadableStream({ + start(controller) { + function push() { + reader.read().then(({ done, value }) => { + if (done) { + controller.close() + return + } + + controller.enqueue(value) + push() + }) + } + + push() + }, + }) + + const data = new Response(stream, { + headers: { 'Content-Type': 'application/pdf' }, + }) + data.blob().then(blob => { + blobToDataURI(blob).then(data => { + this.pdfSource = data + }) + }) + }) + }, handleSwitchUrl(key) { this.pdfSource = TEST_URL_MAP[key] }, @@ -61,9 +99,8 @@ export default { const file = e.target.files[0] - blobToDataURI(file).then(data => { - this.pdfSource = data - }) + const url = URL.createObjectURL(file) + this.pdfSource = url }, }, }