D
D
danilr2020-02-02 06:34:39
JavaScript
danilr, 2020-02-02 06:34:39

How to subscribe to the appearance of a block in Vue / pure js?

There is a method that, when the button is clicked, changes the content. And there is another method that is called in the first method and interacts with a block with a specific id. The problem is that for some reason the blocks do not have time to be drawn, so the script does not find the required div and an error occurs.
The question is how to subscribe to the rendering of the desired div in Vue and pure js?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-02-02
@Kozack

https://developer.mozilla.org/ru/docs/Web/API/Muta...
Or, if possible, call the event
https://developer.mozilla.org/en-US/docs/Web/ inside the component API/C...

Y
Yaroslav Serbin, 2020-02-02
@ATLANT1S

Your problem is not entirely clear. Vue has a watch - watch. You can watch anything change and when it happens, take some action.

<div id="app">
  {{message}}
  <button @click="changeText">Изменить текст</button>

  <div v-if="changed">Текст изменился</div>
</div>

new Vue({
  el: "#app",
  data: {
    message: 'Hello world',
    changed: false
  },
  watch: {
    message: function() {
    	 this.changed = true;
    }
  },
  methods: {
    changeText: function(){
    	this.message = "Привет мир";
    }
  }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question