我在A.vue文件中的temple标签里写<div id="main"></div>,在script标签里直接写var myChart = echarts.init(document.getElementById('main')),然后在B.vue文件中import A.vue,然后就报错了,说没有找到main这个dom元素,请问这种情况该如何解决比较好呢?
1 回答
有只小跳蛙
TA贡献1824条经验 获得超8个赞
main.js
import echarts from "echarts"
A.vue
HTML
<div id="charts"> <div id="main" :style="{width:'600px',height:'400px'}"></div> </div>
javascript
export default{ data (){ return { msg:"123" } }, mounted (){ var myChart = echarts.init(document.getElementById('main')); myChart.setOption({ title: { text: 'ECharts 入门示例' }, tooltip: {}, xAxis: { data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"] }, yAxis: {}, series: [{ name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] }] }); } }
添加回答
举报
0/150
提交
取消