I
I
Intelix2021-11-20 14:38:35
Vue.js
Intelix, 2021-11-20 14:38:35

How to change the styles of elements in vue when clicking on the parent?

I have this toggle switch to switch languages

<div class="lang-changer">
        <div class="lang-tog"><span id="current-lang">РУ</span><span class="lang-tog-circle"></span></div>
      </div>

How do I change styles when clicking on the toggle switch #current-lang ; .lang-tog-circle and .lang-tog

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-11-20
@Intelix

<div class="lang-changer" @click="toggle = !toggle">
  <div :class="toggle ? 'lang-tog': 'lang'">
    <span :class="toggle ? 'a': 'b'">РУ</span>
    <span :class="toggle ? 'x': 'y'"></span>
  </div>
</div>

data(){
  return {
    toggle: false;
  }
}

True, it’s better to change the styles of nested spans simply through css, relative to the top one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question