downloadFile.vue 748 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. onLoad(option) {
  15. const downloadTask = uni.downloadFile({
  16. url: option.url,
  17. success: (res) => {
  18. if (res.statusCode === 200) {
  19. uni.openDocument({
  20. filePath: res.tempFilePath,
  21. showMenu: true, //是否显示右上角菜单
  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></style>