feat:完善舆情监测功能
This commit is contained in:
28
src/hooks/echart.js
Normal file
28
src/hooks/echart.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { ref } from 'vue'
|
||||
import * as echarts from 'echarts'
|
||||
import { guid } from '@/utils/util'
|
||||
|
||||
export function useEchart() {
|
||||
let chart = ref(null)
|
||||
let id = ref(guid())
|
||||
const initChart = () => {
|
||||
const dom = document.getElementById(id.value)
|
||||
chart.value = echarts.init(dom)
|
||||
}
|
||||
const setOption = (params) => {
|
||||
chart.value.setOption(params)
|
||||
}
|
||||
const resize = () => {
|
||||
if (chart) {
|
||||
chart.dispose()
|
||||
chart = null
|
||||
initChart()
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
// 监听窗口大小变化
|
||||
window.addEventListener('resize', resize)
|
||||
})
|
||||
|
||||
return { id, chart, setOption, initChart }
|
||||
}
|
||||
Reference in New Issue
Block a user