echart 错误:Error in mounted hook: "Error: Initialize failed: invalid dom."
-
原因:初始化没有获取到元素
-
方法:初始化的时候,使用
$nextTick
延后执行mounted() { this.init(); }, methods: { init() { this.$nextTick(() => { this.initPic(); }); }, initPic() { const chartDom = this.$refs.echartPicRef; const myChart = echarts.init(chartDom); const option = { xAxis: { type: "category", data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], }, yAxis: { type: "value", }, series: [ { data: [150, 230, 224, 218, 135, 147, 260], type: "line", }, ], }; option && myChart.setOption(option); }, }