ElemeFE / v-charts

基于 Vue2.0 和 ECharts 封装的图表组件📈📊
https://v-charts.js.org
MIT License
6.8k stars 1.98k forks source link

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

Open coder0608 opened 2 years ago

coder0608 commented 2 years ago

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

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

FoliageOwO commented 2 years ago

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

neptoo commented 2 years ago

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

xuwu125 commented 2 years ago

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

都四年没有更新了

Meqn commented 1 year ago

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

xubillde commented 1 year ago

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

Meqn commented 1 year ago

@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 commented 1 year ago

@Meqn 好的,多谢

millerliang commented 1 year ago

@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 commented 1 year ago

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

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

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

多个Vue对象同理

MrKrisYu commented 1 year ago

亲测,可用

GitHuberLearn commented 1 year ago

亲测,可用

chaoming007 commented 11 months ago

亲测,可用

dava060 commented 3 weeks ago

亲测,可用