V
V
Vladislav2020-08-05 11:23:05
Vue.js
Vladislav, 2020-08-05 11:23:05

How to add a class to another element when clicking on a button in Vue?

How to add a class to another element when clicking on a button in Vue, for example, on the body when clicking on the button, the active class is hung?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-05
@SlavaMaxwell

for example on body

Since body should not be used as the root element of the application, it's the same as without vue - by directly accessing classList :
<button @click="onClick">
methods: {
  onClick() {
    document.body.classList.toggle('active');
  },
},

If not "for example" - read the documentation, everything is there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question