核心:
// 监听窗口变化
window.onresize = function () {
myChart.resize()
}
全部代码:
<template>
<div class="trend-line">
<div id="trend-line"></div>
</div>
</template>
<script>
export default {
name: 'TrendLine',
props: [],
components: {},
data() {
return {
}
},
mounted() {
this.getCharts();
},
methods: {
getCharts() {
let myChart = this.$echarts.init(document.getElementById('trend-line'))
myChart.setOption({
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}]
});
// 监听窗口变化
window.onresize = function () {
myChart.resize()
}
}
},
}
</script>
<style lang="scss" scoped>
.trend-line {
height: 100%;
#trend-line {
height: 100%;
width: 100%;
}
}
</style>