const unwarp = (obj) => obj && (obj.__v_raw || obj.valueOf() || obj);
unwarp(this.chart).setOption(this.getOption());
<div id="app"> <div id="chart-demo"></div> </div> <script> import { createApp } from 'vue'; import * as echarts from "echarts"; const unwarp = (obj) => obj && (obj.__v_raw || obj.valueOf() || obj); createApp({ data(){ return { chart:null } }, mounted{ let dom = document.getElementById("chart-demo"); this.chart = echarts.init(dom); unwarp(this.chart).setOption(this.getOption()); }, methods:{ getOption(){ return { xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] }, yAxis: { type: 'value' }, tooltip:{}, series: [{ data: [150, 230, 224, 218, 135, 147, 260], type: 'line' }] }; } } }).mount("#app"); </script>
转载:https://blog.csdn.net/xy109/article/details/113869790