K
K
kroha30002019-08-07 16:40:43
css
kroha3000, 2019-08-07 16:40:43

How to replace one style class with another in vue.js?

Started learning vue.js.
My eyes are blurred and I can no longer reason and study objectively, logically. Maybe it just doesn't get through.
Can't change class on click. Add class adds. I can't replace. Well, or delete after adding.
I re-read the documentation up and down, apparently I already drove myself. but I can't solve the problem. Tell me how to remove or change the style class when clicking on a link/button.
ps I understand that the question is extremely simple. But I can't get over

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrej Sharapov, 2019-08-07
@kroha3000

<div id="app">
  <div :class="{ active }"></div>
  <button @click="active = !active">Toggle Active</button>
</div>

new Vue({
  el: '#app',
  data() {
    return {
      active: false,
    }
  }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question