소스 검색

生词组件宽度计算错误问题

natasha 1 주 전
부모
커밋
4cb275789c
1개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 4 2
      src/views/book/courseware/preview/components/new_word/NewWordPreview.vue

+ 4 - 2
src/views/book/courseware/preview/components/new_word/NewWordPreview.vue

@@ -1163,8 +1163,10 @@ export default {
     },
   },
   mounted() {
-    let totalWidth = document.querySelector('.newWord-preview').offsetWidth;
-    this.width = `${totalWidth - (this.data.property.sn_display_mode === 'true' ? 15 : 0)}px`;
+    this.$nextTick(() => {
+      let totalWidth = document.querySelector('.newWord-preview').offsetWidth;
+      this.width = `${totalWidth - (this.data.property.sn_display_mode === 'true' ? 15 : 0)}px`;
+    });
 
     this.dataHeight = this.$refs.previewContainer.style.height;
   },