当出现FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory的时候,可以用memory工具排查出异常内存并无法手动清除的页面,如果是有涉及echarts的图表,可以考虑是否加上了销毁和重新加载数据的步骤
// 重新渲染图表(调取接口新数据后,再进行刷新图表)
private reRender() {
this.$nextTick(() => {
let chart = this.$refs["chart"];
this.chart = echarts.init(chart as HTMLDivElement);
this.chart.removeAttribute("_echarts_instance_"); // 移除容器标签的 '_echarts_instance_' 实例属性,使用 echarts.init 重新生成一个新的实例 ID
this.initCharts();
});
}
// 销毁图表
private beforeDestroy() {
if (!this.chart) return;
this.chart.dispose();
this.chart = null;
}
// 监听数据变化,重新渲染图表
@Watch("chartData", { deep: true })
private change(value: Array<any>) {
if (value && value.length > 0) {
this.reRender();
}
}