echarts大屏如何实现自适应缩放

核心代码

const dataScreenRef = (ref < HTMLElement) | (null > null);

onMounted(() => {
  if (dataScreenRef.value) {
    dataScreenRef.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
  }
  console.log("dataScreenRef ========> ", dataScreenRef);
  window.addEventListener("resize", resize);
});

// 设置响应式
const resize = () => {
  if (dataScreenRef.value) {
    dataScreenRef.value.style.transform = `scale(${getScale()}) translate(-50%, -50%)`;
    console.log(1111);
  }
};

// 根据浏览器大小推断缩放比例
const getScale = (width = 1920, height = 1080) => {
  let ww = window.innerWidth / width;
  let wh = window.innerHeight / height;
  return ww < wh ? ww : wh;
};
posted @ 2024-11-13 17:46  ajajaz  阅读(4)  评论(0编辑  收藏  举报