<template>
<div id="echarts168" :style="{width: nwidth+'%', height: nheight+'px'}"></div>
</template>
<script lang="ts">
import * as echarts from 'echarts'
import {onMounted, defineComponent, nextTick } from 'vue'
const props = {
ewidth: {
type: Number ,
default: 100
},
eheight: {
type: Number,
default: 440
}
}
export default defineComponent({
props,
setup (props:any, context) {
console.log(context)
let {ewidth: nwidth, eheight: nheight} = props
const initCharts = () => {
console.log('init charts')
const option = {
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'
}
]
};
const myChart = echarts.init(document.getElementById('echarts168') as HTMLDivElement);
myChart.setOption(option)
window.onresize = () => {
myChart.resize()
};
}
onMounted(() => {
initCharts()
})
// 向外暴露初始化方法
context.expose({
initCharts
})
return {
nwidth,
nheight
}
}
})
</script>
04-16
170