解决办法:
标签上使用 v-show,在mounted中this.$nextTick包裹定时器,定时器中写获取ref的元素
<div class="firstTitle" v-show="showThree=='治理成效'">
<div class="leftContent"> </div>
<div class="rightContent">
<div class="listContent"></div>
</div>
</div>
mounted(){
this.$nextTick(()=>{
// setTimeout(() => {
this.getLeftEcharts()
// }, 5000);
})
},
methods:{
//获取柱状图
getLeftEcharts(){
// debugger
let _this = this
let oneEcharts = _this.$echarts.init(this.$refs.leftBarEchart)
let option = {
xAxis: {
type: 'category',
data: ['2017年', '2018年', '2019年', '2020年', '2021年']
},
yAxis: {
type: 'value'
},
series: [
{
data: [2900, 2700, 2400, 1700, 1100, 900],
type: 'bar'
}
]
}
oneEcharts.setOption(option)
}
}