目录1、错误说明2、错误原因3、解决方案1、错误说明 vue3中,使用data的方式初始化echart图表 export default { data() { retur
vue3中,使用data的方式初始化echart图表
export default {
data() {
return {
chart: null,
...
}
},
mounted() {
this.chart = echarts.init(document.getElementById(this.id))
this.chart.setOption({...})
},
...
}
在窗口大小发生变化时,需要执行this.chart.resize()
动态调整图表的大小,发生错误:
Vue3中使用proxy的方式监听响应式,this.chart会被在vue内部转换成响应式对象,从而在resize 的时候获取不到
coordSys.type
参考官方:
你可以有选择地退出默认的深度响应式/只读转换模式,并将原始的,未被代理的对象嵌入状态图中。它们可以根据情况灵活运用:
所以在实例化echart时,将其指定为非响应式的即可。
import { markRaw } from 'vue'
this.chart = markRaw(echarts.init(document.getElementById(this.id)))
随着vue3.2版本的发布以及setup语法的出现,这些已经都不是问题啦,赞美vue
到此这篇关于vue3+echart5 遇到的坑 Cannot read properties of undefined (reading 'type')的文章就介绍到这了,更多相关vue3报错Cannot read properties of undefined内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: 关于vue3+echart5 遇到的坑 Cannot read properties of undefined (reading 'type')
本文链接: https://www.lsjlt.com/news/209659.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0