$nextTick
setTimeout
destroyed()
这些能用的都用了,还是不管用,依旧报错
之前是这样子的。但是他刷新会有问题就改了外层样式,使用百分比,再把echarts放进去就开始报错了。
html
<div class="main-cont">
<a-row :gutter="16" class="cont-tone">
<a-col :span="18">
<div class="echarts-box">
<div
:style="{
width: '100%',
height: '324px',
backgroundColor: '#f0fff9',
}"
ref="myChart2"
></div>
</div>
</a-col>
<a-col :span="6">
</a-col>
</a-row>
js
updated() {
this.setChart4();
this.setChart1(this.echartsData, this.cName);
this.setChart2();
this.setChart3();
},
mounted() {
this.$nextTick(() => {
console.log(this.$refs.myChart2); // 可以获取到
this.setChart4();
this.setChart1(this.echartsData, this.cName);
this.setChart2();
this.setChart3();
});
// setTimeout(()=>{
// this.setChart4();
// this.setChart1(this.echartsData, this.cName);
// this.setChart2();
// this.setChart3();
// },50)
},
destroyed () {
window.removeEventListener('resize', this.setChart2, 20)
},
methods: {
// 柱形
setChart2() {
var myChart2 = this.$echarts.init(this.$refs.myChart2);
window.addEventListener("resize", function() {
myChart2.resize();
});
myChart2.setOption({
// options
});
},
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…