siteList数据由父组件发起异步请求后获得并传递给子组件,但是在mounted等生命周期中调用初始化echarts图表的方法initChart(),确无法正常渲染,此时使用watch深度监听siteList并在handler函数中调用initChart()便可正常渲染。
props:['siteList'],
watch: {
siteList: {
deep: true,
immediate: true,
handler () {
// 初始化图表
this.initChart()
}
}
},
methods: {
initChart() {
const chart = echarts.init(document.getElementById('VulnerabilityRanking'))
const options = this.getChartOptions()
chart.setOption(options)
},
}