up
This commit is contained in:
24
src/hooks/useEcharts.js
Executable file
24
src/hooks/useEcharts.js
Executable file
@ -0,0 +1,24 @@
|
||||
import { onActivated, onDeactivated, onBeforeUnmount } from "vue";
|
||||
// import echarts from "@/plugins/echarts";
|
||||
export const useEcharts = (myChart, options) => {
|
||||
if (options && typeof options === "object") {
|
||||
myChart.setOption(options);
|
||||
}
|
||||
const echartsResize = () => {
|
||||
myChart && myChart.resize();
|
||||
};
|
||||
|
||||
window.addEventListener("resize", echartsResize);
|
||||
|
||||
onActivated(() => {
|
||||
window.addEventListener("resize", echartsResize);
|
||||
});
|
||||
|
||||
onDeactivated(() => {
|
||||
window.removeEventListener("resize", echartsResize);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("resize", echartsResize);
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user