vue解决echarts升级后本地无法启动
1.老项目原来使用的echarts是v4版本,现升级至v5版本
首先根据echarts官方文档升级
npm install echarts --save
然后修改 引用方式
import * as echarts from 'echarts';
2.完成后使用本地启动
使用npm run serve启动项目,出现报错:
module build failed (from ./node_modules/@vue/cli-plugin-babel/node_modules/babel-loader/lib/index.js):
error: c:\users\src\util\table-sort.js: you gave us a visitor for the node type staticblock but it's not a valid type at verify (c:\users\node_modules\@vue\cli-plugin-babel\node_modules\@babel\traverse\lib\visitors.js:116:13)
3.解决方法
升级@vue\cli-plugin-babel的版本
npm install @vue\cli-plugin-babel
4.我的项目中使用了vue-video-player
升级其它插件后还经常出现找不到样式文件(video.js/dist/video-js.css),此时重装对应版本即可
npm i vue-video-player@5.0.2
echarts4升级echarts5升级记录
升级后优点,默认样式更好看,动效体验更好。
缺点,容错率降低,需要处理新版不支持的代码
1.y周label的纵向位置调整 负值padding不生效

- 旧:
axislabel: {
padding:[-13,0,0,0],
}
- 新:
axislabel: {
padding:[-13,0,0,0],
verticalalign: 'top',
}
2.自定义y轴最大值max与最小值min
- 旧:min/max写反也能正常使用
- 新:无法正常使用
3.饼图label位置调整到引导线上方

- 旧:padding左右双边设为负值
label: {
normal: {
textstyle: {
lineheight: 14,
fontsize: 12,
padding: [0, -43]
}
}
},
labelline: {
show: true,
length: 10,
length2: 45
},
- 新:第二段结束点需自行计算
label: {
normal: {
textstyle: {
lineheight: 14,
fontsize: 12,
}
}
},
labelline: {
show: true,
length: 10,
length2: 0
},
labellayout: (params)=> {
const isleft = params.labelrect.x < canvas.getwidth() / 2;
const points = params.labellinepoints;
points[2][0] = isleft ? params.labelrect.x : params.labelrect.x + params.labelrect.width;
return {
labellinepoints: points,
};
},
4.饼图引导线指向中间

- 旧:labelline的length设为负值
labelline: {
show: true,
length: -35,
length2: -35,
},
- 新:第二段结束点需自行计算
label: {
padding: [0, -35],
},
labelline: {
show: true,
length: -35,
length2: 0,
},
labellayout: function (params) {
let center = position[0]//饼图中心x位置
const points = params.labellinepoints;
//points line的三个点的x,y位置
const isleft = points[1][0] <= center;
points[2][0] = isleft ? points[1][0] + 35 : points[1][0] - 35
return {
labellinepoints: points,
};
},
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论