Echarts, Adaptive error reporting is introduced into vue


you will not report an error when you just enter this page, but you will only report an error if you reduce the size of the page.
has successfully introduced jquery

Mar.23,2021

the current this is pointing incorrectly. The current this points to the inside of the monitor. You should use the outside pointer after let _ this=this;.


this points to

for reference only

<template>
  <div :class="className" :style="{height:height,width:width}"></div>
</template>


<script>
import echarts from "echarts";
import { debounce } from "@/utils";

export default {
  props: {
    className: {
      type: String,
      default: "chart"
    },
    width: {
      type: String,
      default: "100%"
    },
    height: {
      type: String,
      default: "280px"
    },
    // 
    legendData: {
      type: Array
    },
    // 
    series: {
      type: Array
    },
    // 
    title: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      chart: null
    };
  },
  watch: {
    // 
    title(val) {
      this.reDraw();
    },
    // 
    series(val) {
      this.reDraw();
    },
    // 
    legendData(val) {
      this.reDraw();
    }
  },
  mounted() {
    this.initChart();
    this.__resizeHanlder = debounce(() => {
      if (this.chart) {
        this.chart.resize();
      }
    }, 100);
    window.addEventListener("resize", this.__resizeHanlder);
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    window.removeEventListener("resize", this.__resizeHanlder);
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        title: {
          text: this.title,
          left: "center",
          bottom: 0,
          textStyle: {
            color: "black",
            fontSize: 14
          }
        },
        labelLine: {
          normal: {
            smooth: 0.2,
            length: 0,
            length2: 0
          }
        },
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
          left: "center",
          bottom: 40,
          textStyle: {
            color: "-sharp999",
            fontSize: 12
          },
          data: this.legendData
        },
        calculable: true,
        series: this.series
      });
    },
    // 
    reDraw() {
      if (!this.chart) {
        return;
      }
      window.removeEventListener("resize", this.__resizeHanlder);
      this.chart.dispose();
      this.chart = null;
      this.initChart();
    }
  }
};
</script>

<style lang="scss" scoped>

</style>

export function debounce(func, wait, immediate) {
  let timeout, args, context, timestamp, result

  const later = function () {
    // 
    const last = +new Date() - timestamp

    // lastwait
    if (last < wait && last > 0) {
      timeout = setTimeout(later, wait - last)
    } else {
      timeout = null
      // immediate===true
      if (!immediate) {
        result = func.apply(context, args)
        if (!timeout) context = args = null
      }
    }
  }

callback function uses arrow function,

window.addEventListen("resize", () => {
    this.chart.resize();
})
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b527-2b202.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b527-2b202.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?