FileDownloadButton.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <span @click="downloadFile()" ><i class="fa fa-cloud-download" aria-hidden="true"></i> {{ name }}</span>
  3. </template>
  4. <script>
  5. import Base from "@/views/base/Base"
  6. import { delAttament, downloadFile } from '@/api/file'
  7. export default {
  8. extends: Base,
  9. data() {
  10. return {
  11. }
  12. },
  13. props: {
  14. text: {
  15. type: String,
  16. default: '8a2e26f5ca95419a9cd356a4968cebc4.jpg'
  17. },
  18. module: {
  19. type: String,
  20. default: 'http://localhost:8080/api/file/pub'
  21. },
  22. name: {
  23. type: String,
  24. default: ''
  25. }
  26. },
  27. methods: {
  28. downloadFile: function() {
  29. if (!this.name) {
  30. alert("暂时无法下载");
  31. }
  32. var path = this.module + '/' + this.name;
  33. var fileName = this.text;
  34. downloadFile({
  35. path,
  36. fileName
  37. }).then(res => {
  38. this.download(res);
  39. }).catch(err => {
  40. if (err.msg) {
  41. alert(err.msg);
  42. }
  43. console.log(err);
  44. });
  45. }
  46. }
  47. }
  48. </script>