A
A
ABCquestion2022-01-06 15:26:30
Vue.js
ABCquestion, 2022-01-06 15:26:30

In which lifecycle hook should the screen size check be done?

I want to add a class to an element on a mobile phone, how to do it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Kudryavtsev, 2022-01-06
@Deissh

Looking what logic follows after check.
And somounted

mounted() {
  this.$nextTick(function () {
    // код будет вызван после того как будут отрисованы все дочерние компоненты
  })
}

A
Aetae, 2022-01-06
@Aetae

On any. You need a prototype\plugin\global mixin extension that will take care of this itself, and in the component just use it.
It makes no sense to write this logic in one component, because it will definitely be needed in another.
For example .
If you really want to, then you createdhang the handler on resize(or better mediaQuery addListener\ onchangetime you have a specific breakpoint), destroyedyou must remove the handler on. The handler itself sets some variable in data.

M
markmariner, 2022-01-11
@markmariner

You should use CSS media queries .
It's good when the JS code is preparing data for display and processing it after user input, but knows nothing about how exactly this data will be displayed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question