如何在Vuejs中使2个组件同时安装?

I use window.onresize in mounted in 2 different component. When the window change the size, it will run the code in window.onresize but it only run 1 component, not 2 component the same time.

How can I make it run both window.onresize in 2 component a same time?

mounted() {
  window.onresize = () => {
    this.productDetailRatio = window.innerWidth / 1900;
    this.screenWidth = window.innerWidth;
    this.productDetailRatiofont =
      window.innerWidth / 1900 < 0.5 ? 0.5 : window.innerWidth / 1900;
  };
}

我在2个不同的组件中使用了此控件,并且当我更改窗口大小时,我希望它们都在2个组件中运行,但它只能工作1个组件。

评论