Using the Vue.nextTick function

In this article, you will learn about the Vue.nextTick callback function and when to make use of it. In plain terms, Vue.nextTick gives you access…

The post Using the Vue.nextTick function appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Prince Chukwudire

In this article, you will learn about the Vue.nextTick callback function and when to make use of it.

In plain terms, Vue.nextTick gives you access to the data instance after it has been updated, the new changes effected on the DOM but not yet rendered on the web page.

We can visualize its role by updating our data instance during the mounted life cycle hook and catching its effect midway.

<template>
  <div>
    {{ msg }}
  </div>
</template>

<script>
export default {
    data() {
    return {
      msg: "First Message",
    };
  },
  mounted() {
    this.msg = "Second message";
  },
};
</script>

This would update our instance and render the new message. Let’s add the Vue.nextTick function, refresh our page and observe the change.

<template>
  <div>
    {{ msg }}
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      msg: "First Message",
    };
  },
  mounted() {
    this.msg = "Second message";

    this.$nextTick(() => {
      this.msg = "Third message";
    });
  },
};
</script>

  

When we reload the page we see the third message rendered.

The post Using the Vue.nextTick function appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Prince Chukwudire


Print Share Comment Cite Upload Translate Updates
APA

Prince Chukwudire | Sciencx (2021-03-04T08:02:39+00:00) Using the Vue.nextTick function. Retrieved from https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/

MLA
" » Using the Vue.nextTick function." Prince Chukwudire | Sciencx - Thursday March 4, 2021, https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/
HARVARD
Prince Chukwudire | Sciencx Thursday March 4, 2021 » Using the Vue.nextTick function., viewed ,<https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/>
VANCOUVER
Prince Chukwudire | Sciencx - » Using the Vue.nextTick function. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/
CHICAGO
" » Using the Vue.nextTick function." Prince Chukwudire | Sciencx - Accessed . https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/
IEEE
" » Using the Vue.nextTick function." Prince Chukwudire | Sciencx [Online]. Available: https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/. [Accessed: ]
rf:citation
» Using the Vue.nextTick function | Prince Chukwudire | Sciencx | https://www.scien.cx/2021/03/04/using-the-vue-nexttick-function/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.