v-charts icon indicating copy to clipboard operation
v-charts copied to clipboard

引入任意图表的时候报错 :map undefined

Open coder0608 opened this issue 2 years ago • 13 comments

Error in created hook: "TypeError: Cannot read properties of undefined (reading 'map')"

备注:直接拿官方文档例子,也报这种错误

coder0608 avatar Aug 16 '22 03:08 coder0608

同样错误,我怀疑是不支持最新 vue3,vue2 测试没问题

FoliageOwO avatar Aug 21 '22 12:08 FoliageOwO

同样遇到这个问题 官方不打算修复吗

neptoo avatar Aug 24 '22 06:08 neptoo

同样遇到这个问题 官方不打算修复吗

都四年没有更新了

xuwu125 avatar Sep 10 '22 13:09 xuwu125

官方不更新了,直接修改源码 v-charts/lib/core.js ,配合 patch-package

Meqn avatar Dec 05 '22 07:12 Meqn

@Meqn v-charts/lib/core.js内部this._watchers这块要如何改?

xubillde avatar Dec 06 '22 06:12 xubillde

@LDXu

找到 文件 node_modules/v-charts/lib/core.js,具体修改看下面 + 行。 这个文件是修改后通过 patch-package 生成的。

diff --git a/node_modules/v-charts/lib/core.js b/node_modules/v-charts/lib/core.js
index 49d56ac..33c1afe 100644
--- a/node_modules/v-charts/lib/core.js
+++ b/node_modules/v-charts/lib/core.js
@@ -36,7 +36,7 @@ var _extends = Object.assign || function (target) {
 function setExtend (options, extend) {
   Object.keys(extend).forEach(function (attr) {
     var value = extend[attr];
-    if (~attr.indexOf('.')) {
+    if (~attr?.indexOf('.')) {
       // eg: a.b.c a.1.b
       utilsLite.set(options, attr, value);
     } else if (typeof value === 'function') {
@@ -366,11 +366,11 @@ var core = {
     addWatchToProps: function addWatchToProps() {
       var _this3 = this;
 
-      var watchedVariable = this._watchers.map(function (watcher) {
+      var watchedVariable = this._watchers?.map(function (watcher) {
         return watcher.expression;
       });
       Object.keys(this.$props).forEach(function (prop) {
-        if (!~watchedVariable.indexOf(prop) && !~constants.STATIC_PROPS.indexOf(prop)) {
+        if (!~watchedVariable?.indexOf(prop) && !~constants.STATIC_PROPS?.indexOf(prop)) {
           var opts = {};
           if (~['[object Object]', '[object Array]'].indexOf(utilsLite.getType(_this3.$props[prop]))) {
             opts.deep = true;
@@ -390,7 +390,7 @@ var core = {
       var self = this;
       var keys = Object.keys(this.events || {});
       keys.length && keys.forEach(function (ev) {
-        if (_this4.registeredEvents.indexOf(ev) === -1) {
+        if (_this4.registeredEvents?.indexOf(ev) === -1) {
           _this4.registeredEvents.push(ev);
           _this4.echarts.on(ev, function (ev) {
             return function () {

Meqn avatar Dec 07 '22 12:12 Meqn

@Meqn 好的,多谢

xubillde avatar Dec 08 '22 04:12 xubillde

@vue/cli 5.0.8 "vue": "2.6.14" 檔案:/node_modules/v-charts/lib/core.js 行數:Line 370

目前發現 this._watchers 為 undefined 執行 map() 時報錯,+ 加入 *** 判斷條件 ***,改完不會執行 map() 報錯但不保證這樣修改後一定都不會有問題!

 addWatchToProps: function addWatchToProps() {
    var _this3 = this;

    + var watchedVariable = ***this._watchers &&*** this._watchers.map(watcher => {
      return watcher.expression;
    });
    Object.keys(this.$props).forEach(prop => {
      + if (***watchedVariable &&*** !~watchedVariable.indexOf(prop) && !~constants.STATIC_PROPS.indexOf(prop)) {
        var opts = {};
        if (~['[object Object]', '[object Array]'].indexOf(utilsLite.getType(_this3.$props[prop]))) {
          opts.deep = true;
        }
        _this3.$watch(prop, () => {
          _this3.changeHandler();
        }, opts);
      }
    });
  },

millerliang avatar Jan 07 '23 03:01 millerliang

提供一个不修改源码的思路

在App入口文件, Vue对象实例化之前, 加入

Vue._watchers = Vue.prototype._watchers = []

多个Vue对象同理

Hwacc avatar Jan 30 '23 08:01 Hwacc

亲测,可用

MrKrisYu avatar Feb 23 '23 01:02 MrKrisYu

亲测,可用

GitHuberLearn avatar Jun 01 '23 08:06 GitHuberLearn

亲测,可用

chaoming007 avatar Sep 26 '23 01:09 chaoming007