Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <a @click.prevent="download" href><span v-show="showIcon" class="glyphicon glyphicon-download"></span> Download</a>
- </template>
- <script>
- import { saveAs } from 'file-saver';
- export default {
- props: ['file', 'showIcon'],
- methods: {
- download () {
- axios.get(this.file.url, {responseType: 'arraybuffer'})
- .then((response) => {
- let filename = response.headers['content-disposition'].match(/filename="(.+)"/)[1];
- let file = new Blob([response.data], {type: response.headers['content-type']});
- saveAs(file, filename);
- })
- .catch(console.log);
- },
- }
- }
- </script>
Add Comment
Please, Sign In to add comment