v-charts
v-charts copied to clipboard
引入任意图表的时候报错 :map undefined
Error in created hook: "TypeError: Cannot read properties of undefined (reading 'map')"
备注:直接拿官方文档例子,也报这种错误
同样错误,我怀疑是不支持最新 vue3,vue2 测试没问题
同样遇到这个问题 官方不打算修复吗
同样遇到这个问题 官方不打算修复吗
都四年没有更新了
官方不更新了,直接修改源码 v-charts/lib/core.js
,配合 patch-package
@Meqn v-charts/lib/core.js内部this._watchers这块要如何改?
@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 好的,多谢
@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);
}
});
},
提供一个不修改源码的思路
在App入口文件, Vue对象实例化之前, 加入
Vue._watchers = Vue.prototype._watchers = []
多个Vue对象同理
亲测,可用
亲测,可用
亲测,可用