소스 검색

Fix highchart error on update before mounted.

Dominique CLAUSE 2 년 전
부모
커밋
6f2d3fa0b1
1개의 변경된 파일16개의 추가작업 그리고 3개의 파일을 삭제
  1. 16 3
      nicegui/elements/chart.js

+ 16 - 3
nicegui/elements/chart.js

@@ -9,12 +9,25 @@ export default {
       });
     }, 0); // NOTE: wait for window.path_prefix to be set in app.mounted()
   },
+  beforeDestroy() {
+    this.destroyChart();
+  },
+  beforeUnmount() {
+    this.destroyChart();
+  },
   methods: {
     update_chart() {
-      while (this.chart.series.length > this.options.series.length) this.chart.series[0].remove();
-      while (this.chart.series.length < this.options.series.length) this.chart.addSeries({}, false);
-      this.chart.update(this.options);
+      if (this.chart) {
+        while (this.chart.series.length > this.options.series.length) this.chart.series[0].remove();
+        while (this.chart.series.length < this.options.series.length) this.chart.addSeries({}, false);
+        this.chart.update(this.options);
+      }
     },
+    destroyChart () {
+      if (this.chart) {
+        this.chart.destroy()
+      }
+    }
   },
   props: {
     type: String,