I have a question, I am developing an application with Vuejs and I need to export files of any type (pdf, txt, xlsx), but no matter what, I always get this error when I try to use this function, I put a simple example of a file that should be able to download as a test:
var blob = new Blob(['Hello, world!'], { type: 'text/plain;charset=utf-8' })
saveAs(blob, 'hello.txt')
the saveAs function I get it from the 'file-saver' library.
Edit
Component.vue
<template>
<Button @click="export">Export</Button>
</template>
I simply have a button that calls the export function
export: function () {
var blob = new Blob(['Hello, world!'], { type: 'text/plain;charset=utf-8' })
saveAs(blob, 'hello.txt')
},
I just realized that this works fine when in production, but not in the local environment. Why does this happen?
Ok, after looking for a possible solution I found that the problem is this function:
URL.createObjectURL(blob)
No matter how I use it, either directly or through a library the error was always here. The way I solved it was by changing the previous function for this one:
window.webkitURL.createObjectURL(blob)
At least this worked for me, I hope it can help someone else who has the same problem.