Procházet zdrojové kódy

修复在渲染富文本时为获取到高度的问题

xiaohaizhao před 1 rokem
rodič
revize
e4c3ccdfe4
1 změnil soubory, kde provedl 30 přidání a 22 odebrání
  1. 30 22
      pages/index/annunciate/index.js

+ 30 - 22
pages/index/annunciate/index.js

@@ -60,29 +60,37 @@ Component({
         this.rander(lookItem.content)
       });
     },
-    rander(html) {
-      this.setHeight();
-      if (editor == null) {
-        wx.createSelectorQuery().in(this).select('#editor').context(function (res) {
-          editor = res.context;
-          this.rander(html)
-        }).exec()
-      } else {
-        editor.setContents({
-          html,
-          complete: res => {
-            console.log("渲染富文本", res)
-          }
-        })
-      };
+    async rander(html) {
+      this.setHeight().then(s => {
+        if (editor == null) {
+          wx.createSelectorQuery().in(this).select('#editor').context(function (res) {
+            editor = res.context;
+            this.rander(html)
+          }).exec()
+        } else {
+          editor.setContents({
+            html,
+            complete: res => {
+              console.log("渲染富文本", res)
+              if (this.data.height == 0) setTimeout(() => {
+                this.rander(html)
+              }, 50)
+            }
+          })
+        };
+      })
+
     },
-    async setHeight() {
-      let boxHeight = await this.queryElement(".box", "height"),
-        headHeight = await this.queryElement(".head", "height"),
-        bottomHeight = await this.queryElement(".bottom", "height"),
-        height = boxHeight - headHeight - bottomHeight - 5;
-      this.setData({
-        height
+    setHeight() {
+      return new Promise(async (resolve) => {
+        let boxHeight = await this.queryElement(".box", "height"),
+          headHeight = await this.queryElement(".head", "height"),
+          bottomHeight = await this.queryElement(".bottom", "height"),
+          height = boxHeight - headHeight - bottomHeight - 5;
+        this.setData({
+          height
+        })
+        resolve(height)
       })
     },
     queryElement(element, field) {