浏览代码

分享功能耗时优化

任一存 2 年之前
父节点
当前提交
bf100e5ae3
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      src/views/gui/Share.vue

+ 4 - 4
src/views/gui/Share.vue

@@ -142,7 +142,7 @@ export default {
   methods: {
     onClickSave: globalUtils.throttle(function() {
       this.isSaving = true
-      setTimeout(() => {
+      this.$nextTick(() => {
         // #capture 就是我们要获取截图对应的 DOM 元素选择器
         html2canvas(document.querySelector('#capture'), {
           useCORS: true, // 【重要】开启跨域配置
@@ -151,12 +151,12 @@ export default {
           preserveDrawingBuffer: true,
         }).then((canvas) => {
           this.aDownloadHref = canvas.toDataURL('image/jpeg', 1.0)
-          setTimeout(() => {
+          this.$nextTick(() => {
             this.$refs['for-download'].click()
             this.isSaving = false
-          }, 300)
+          })
         })
-      }, 300) // 这里加上 300ms 的延迟是为了让 DOM 元素完全渲染完成后再进行图片的生成
+      })
     }, 400)
   }
 }