iis服务器助手广告
返回顶部
首页 > 资讯 > 前端开发 > JavaScript >关于vue3+echart5 遇到的坑 Cannot read properties of undefined (reading 'type')
  • 575
分享到

关于vue3+echart5 遇到的坑 Cannot read properties of undefined (reading 'type')

vue3报错Cannot read properties of undefinedvue3 echart5报错 2023-05-16 11:05:48 575人浏览 薄情痞子
摘要

目录1、错误说明2、错误原因3、解决方案1、错误说明 vue3中,使用data的方式初始化echart图表 export default { data() { retur

1、错误说明

vue3中,使用data的方式初始化echart图表

export default {
  data() {
    return {
      chart: null,
      ...
    }
  },
  mounted() {
    this.chart = echarts.init(document.getElementById(this.id))
    this.chart.setOption({...})
  },
  ...
}

在窗口大小发生变化时,需要执行this.chart.resize()动态调整图表的大小,发生错误:

2、错误原因

Vue3中使用proxy的方式监听响应式,this.chart会被在vue内部转换成响应式对象,从而在resize 的时候获取不到

coordSys.type

3、解决方案

参考官方:

你可以有选择地退出默认的深度响应式/只读转换模式,并将原始的,未被代理的对象嵌入状态图中。它们可以根据情况灵活运用:

  • 有些值不应该是响应式的,例如复杂的第三方类实例或 Vue 组件对象。
  • 当渲染具有不可变数据源的大列表时,跳过 proxy 转换可以提高性能。

所以在实例化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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作