S
S
salco20122021-12-04 16:29:18
JavaScript
salco2012, 2021-12-04 16:29:18

How to get window.screen.width in computed on every change?

I have a computed property that is responsible for the number of rows for cards. And this property should return the number of rows depending on the width of the window, the problem is that this only works 1 time, when the page is updated, and I need to receive an update of the computed property every time the width changes through devtools, even by 1 px. Help solve the problem))

countRanks() {
      const screenWidth = window.screen.width;
      console.log(screenWidth);
      if (screenWidth >= 992 && screenWidth < 1200) {
        return 3;
      }
      if (screenWidth >= 768 && screenWidth < 992) {
        return 2;
      }
      if (screenWidth > 0 && screenWidth < 768) {
        return 1;
      }
      return 4;
    },
  },


Works only 1 time when updating;
<p>countRanks</p>

61ab6d053fa67256090283.jpeg

If I change the width, the value does not change, although it should return 1
61ab6d156e570663796112.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Johnny Gat, 2021-12-04
@salco2012

https://qna.habr.com/q/419566

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question