feat:对接接口、完善功能
This commit is contained in:
@@ -3,26 +3,27 @@ import * as echarts from 'echarts'
|
||||
import { guid } from '@/utils/util'
|
||||
|
||||
export function useEchart() {
|
||||
let chart = ref(null)
|
||||
let chart = null
|
||||
let id = ref(guid())
|
||||
const initChart = () => {
|
||||
const dom = document.getElementById(id.value)
|
||||
chart.value = echarts.init(dom)
|
||||
chart = echarts.init(dom)
|
||||
}
|
||||
const setOption = (params) => {
|
||||
chart.value.setOption(params)
|
||||
chart.setOption(params)
|
||||
}
|
||||
const dispose = () => {
|
||||
chart.dispose()
|
||||
chart = null
|
||||
}
|
||||
const resize = () => {
|
||||
if (chart) {
|
||||
chart.dispose()
|
||||
chart = null
|
||||
initChart()
|
||||
}
|
||||
chart.resize()
|
||||
}
|
||||
onMounted(() => {
|
||||
initChart()
|
||||
// 监听窗口大小变化
|
||||
window.addEventListener('resize', resize)
|
||||
})
|
||||
|
||||
return { id, chart, setOption, initChart }
|
||||
return { id, chart, setOption, dispose, initChart }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user