Explorar o código

perf(web): 减少重复字数计算

Xwite %!s(int64=3) %!d(string=hai) anos
pai
achega
dc1104008c
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      modules/web/src/components/ChapterContent.vue

+ 5 - 1
modules/web/src/components/ChapterContent.vue

@@ -3,7 +3,7 @@
   <div
     v-for="(para, index) in contents"
     :key="index"
-    :wordCount="calculateWordCount(para)"
+    :wordCount="wordCounts[index]"
   >
     <img
       class="full"
@@ -43,6 +43,10 @@ const calculateWordCount = (paragraph) => {
   const imagePlaceHolder = " ";
   return paragraph.replaceAll(imgPattern, imagePlaceHolder).length;
 };
+const wordCounts = computed(() => {
+  return Array.from(props.contents, content => calculateWordCount(content));
+});
+
 </script>
 
 <style lang="scss" scoped>