downloadFile.vue 687 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <template>
  2. <view class="progress-box">
  3. <progress :percent="progress" show-info stroke-width="3" />
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. data() {
  9. return {
  10. progress:0
  11. }
  12. },
  13. methods: {
  14. },
  15. onLoad(option) {
  16. const downloadTask = uni.downloadFile({
  17. url: option.url,
  18. success: (res) => {
  19. if (res.statusCode === 200) {
  20. uni.openDocument({
  21. filePath:res.tempFilePath,
  22. })
  23. }
  24. }
  25. });
  26. downloadTask.onProgressUpdate((res) => {
  27. this.progress=res.progress
  28. });
  29. },
  30. onShow() {
  31. if(this.progress==100){
  32. uni.navigateBack()
  33. }
  34. }
  35. }
  36. </script>
  37. <style>
  38. </style>