Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coder0608 opened this issue Aug 16, 2022 · 14 comments
Open

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

coder0608 opened this issue Aug 16, 2022 · 14 comments

Comments

@coder0608
Copy link

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

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

@FoliageOwO
Copy link

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

@neptoo
Copy link

neptoo commented Aug 24, 2022

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

@xuwu125
Copy link

xuwu125 commented Sep 10, 2022

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

都四年没有更新了

@Marinerer
Copy link

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

@xubillde
Copy link

xubillde commented Dec 6, 2022

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

@Marinerer
Copy link

@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 () {

@xubillde
Copy link

xubillde commented Dec 8, 2022

@Meqn 好的,多谢

@millerliang
Copy link

@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);
      }
    });
  },

@Hwacc
Copy link

Hwacc commented Jan 30, 2023

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

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

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

多个Vue对象同理

@MrKrisYu
Copy link

亲测,可用

@GitHuberLearn
Copy link

亲测,可用

2 similar comments
@chaoming007
Copy link

亲测,可用

@dava060
Copy link

dava060 commented Aug 20, 2024

亲测,可用

@mzy-ly
Copy link

mzy-ly commented Oct 24, 2024

image

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

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

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

多个Vue对象同理

牛批!!!在nuxt2中,亲测可用
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests