调用init方法语句写在this.$nextTick(() => {});方法里,因为nextTick方法在页面元素加载完之后调用
this.$nextTick(() => {this.$refs.chartComponent.init();});
如果还报错:Error in nextTick: "TypeError: Cannot read properties of undefined (reading ‘init’)"和Cannot read properties of undefined (reading ‘init’),则先判断组件是否存在,再调用该方法,问题解决。
if (this.$refs.chartComponent) {this.$nextTick(() => {this.$refs.chartComponent.init();});
}