ソースを参照

热更新问题

gcj 3 年 前
コミット
9594ed211b
2 ファイル変更69 行追加48 行削除
  1. 43 36
      src/components/common/Enword.vue
  2. 26 12
      src/components/common/Hanzi.vue

+ 43 - 36
src/components/common/Enword.vue

@@ -157,7 +157,11 @@ export default {
     };
   },
   computed: {},
-  watch: {},
+  watch: {
+    item(newVal, oldVal) {
+      this.this.initFn();
+    },
+  },
   //方法集合
   methods: {
     cancleColl() {
@@ -181,46 +185,49 @@ export default {
       let _this = this;
       _this.curTime = curTime * 1000;
     },
+    initFn() {
+      let _this = this;
+      if (_this.item) {
+        let dict = _this.item.new_word.definition_dictionary_json
+          ? JSON.parse(_this.item.new_word.definition_dictionary_json)
+          : null;
+        _this.dictDetail = dict.data;
+        let arr = [];
+        if (this.dictDetail && this.dictDetail.explains) {
+          this.dictDetail.explains.forEach((it) => {
+            let obj = {
+              part: it.substring(
+                0,
+                it.indexOf(". ") > -1 &&
+                  this.cixingList.indexOf(
+                    it.substring(0, it.lastIndexOf(". ") + 1)
+                  ) > -1
+                  ? it.lastIndexOf(". ") + 2
+                  : 0
+              ),
+              exp: it.substring(
+                it.indexOf(". ") > -1 &&
+                  this.cixingList.indexOf(
+                    it.substring(0, it.lastIndexOf(". ") + 1)
+                  ) > -1
+                  ? it.lastIndexOf(". ") + 2
+                  : 0,
+                it.length
+              ),
+            };
+            arr.push(obj);
+          });
+          this.dictDetail.part = arr;
+          console.log(this.dictDetail);
+        }
+      }
+    },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {},
   //生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {
-    let _this = this;
-    if (_this.item) {
-      let dict = _this.item.new_word.definition_dictionary_json
-        ? JSON.parse(_this.item.new_word.definition_dictionary_json)
-        : null;
-      _this.dictDetail = dict.data;
-      let arr = [];
-      if (this.dictDetail && this.dictDetail.explains) {
-        this.dictDetail.explains.forEach((it) => {
-          let obj = {
-            part: it.substring(
-              0,
-              it.indexOf(". ") > -1 &&
-                this.cixingList.indexOf(
-                  it.substring(0, it.lastIndexOf(". ") + 1)
-                ) > -1
-                ? it.lastIndexOf(". ") + 2
-                : 0
-            ),
-            exp: it.substring(
-              it.indexOf(". ") > -1 &&
-                this.cixingList.indexOf(
-                  it.substring(0, it.lastIndexOf(". ") + 1)
-                ) > -1
-                ? it.lastIndexOf(". ") + 2
-                : 0,
-              it.length
-            ),
-          };
-          arr.push(obj);
-        });
-        this.dictDetail.part = arr;
-        console.log(this.dictDetail);
-      }
-    }
+    this.initFn();
   },
   beforeCreate() {}, //生命周期 - 创建之前
   beforeMount() {}, //生命周期 - 挂载之前

+ 26 - 12
src/components/common/Hanzi.vue

@@ -128,7 +128,11 @@ export default {
     };
   },
   computed: {},
-  watch: {},
+  watch: {
+    item(newVal, oldVal) {
+      this.initFn();
+    },
+  },
   //方法集合
   methods: {
     cancleColl() {
@@ -159,6 +163,7 @@ export default {
       _this.paraphrase = [];
       _this.isHasValue2 = "";
       _this.def_result = "";
+      _this.mp3Url = "";
       _this.dataDetail.forEach((item) => {
         if (item.request.queryType == "entity") {
           // 读音
@@ -173,6 +178,7 @@ export default {
               } else if (itemss.key == "definition") {
                 // 释义
                 _this.paraphrase = itemss.objects;
+                console.log(_this.paraphrase);
                 for (let i = 0; i < _this.paraphrase.length; i++) {
                   if (_this.paraphrase[i]["@definitionWithSpell"]) {
                     _this.isHasValue2 = "definitionWithSpell";
@@ -212,23 +218,31 @@ export default {
           });
         }
       });
-      console.log(_this.isHasValue2);
+      console.log(_this.item.new_word.new_word);
+      console.log(_this.def_result);
+    },
+    initFn() {
+      let _this = this;
+      _this.paraphrase = [];
+      _this.isHasValue2 = "";
+      _this.def_result = "";
+      _this.mp3Url = "";
+      if (_this.item) {
+        let dict = _this.item.new_word.definition_dictionary_json
+          ? JSON.parse(_this.item.new_word.definition_dictionary_json)
+          : null;
+        _this.dataDetail = dict.data.result;
+        if (_this.dataDetail) {
+          _this.handleChineseDetail();
+        }
+      }
     },
   },
   //生命周期 - 创建完成(可以访问当前this实例)
   created() {},
   //生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {
-    let _this = this;
-    if (_this.item) {
-      let dict = _this.item.new_word.definition_dictionary_json
-        ? JSON.parse(_this.item.new_word.definition_dictionary_json)
-        : null;
-      _this.dataDetail = dict.data.result;
-      if (_this.dataDetail) {
-        _this.handleChineseDetail();
-      }
-    }
+    this.initFn();
   },
   beforeCreate() {}, //生命周期 - 创建之前
   beforeMount() {}, //生命周期 - 挂载之前