Guest User

Untitled

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. <template>
  2. <a @click.prevent="download" href><span v-show="showIcon" class="glyphicon glyphicon-download"></span> Download</a>
  3. </template>
  4.  
  5. <script>
  6. import { saveAs } from 'file-saver';
  7. export default {
  8. props: ['file', 'showIcon'],
  9. methods: {
  10. download () {
  11. axios.get(this.file.url, {responseType: 'arraybuffer'})
  12. .then((response) => {
  13. let filename = response.headers['content-disposition'].match(/filename="(.+)"/)[1];
  14. let file = new Blob([response.data], {type: response.headers['content-type']});
  15. saveAs(file, filename);
  16. })
  17. .catch(console.log);
  18. },
  19. }
  20. }
  21. </script>
Add Comment
Please, Sign In to add comment