I
I
Ivan Ivanov2019-09-28 14:48:52
JavaScript
Ivan Ivanov, 2019-09-28 14:48:52

How to access specific elements on a page in Vue.js?

Good afternoon, tell me please. If in js I could assign another class to the example class by doing:
<div class="example">Привет</div>

let dot = document.getElementsByClassName('dot');
dot.classList.add('example2');

or use , then how to do all this in Vue? dot.style.display = 'none',

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-09-28
@IvanInvanov

When you write in view, you must be aware of the state of the data. Roughly speaking, the imperative approach here is not entirely in the subject.
You don't have to write "assign class on click"
Instead you should do this

data() {
  return {
    isShowHelloBlock: false,
  }
}
<div :class="{someClass : isShowHelloBlock}">Hello</div>
<button @click="isShowHelloBlock = true">toggle block</button>

By changing the state, you change the view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question