A
A
Alianos2021-04-18 15:13:21
Vue.js
Alianos, 2021-04-18 15:13:21

How to use computed inside watch in vue + vuex?

Hello, I want to use the computed property (analogous to vmin) in watch. But for some reason, this.getMinSide does not work (if you put just numbers, then everything is ok ... everything is also ok in chrome debugging) What goes wrong))?

computed: {
    getMinSide() {
      if (
        document.documentElement.clientHeight <
        document.documentElement.clientWidth
      ) {
        return document.documentElement.clientHeight;
      } else {
        return document.documentElement.clientWidth;
      }
    },
  },
  watch: {
    "$i18n.locale": () => {
      document.getElementById("frame").style.width =
        (document.getElementById("frame").childNodes[0].scrollWidth * 100) /
          this.getMinSide +
        "vmin";
    },
  },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Glebov, 2021-04-18
@SkiperX

Everything related to dom is not reactive, getMinSide will be calculated once and that's it. Recalculate on the resize event.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question