Categories
Vue Answers

How to access props in mounted function with Vue.js?

Spread the love

Sometimes, we want to access props in mounted function with Vue.js.

In this article, we’ll look at how to access props in mounted function with Vue.js.

How to access props in mounted function with Vue.js?

To access props in mounted function with Vue.js, we can get the value from this.

For instance, we write

<script>
//...
export default {
  //...
  props: ["subscriptions"],
  async mounted() {
    await this.$nextTick();
    console.log(this.subscriptions);
  },
  //...
};
</script>

to register the subscriptions prop with

props: ["subscriptions"]

Then we get the subscriptions prop value in the mounted hook with

this.subscriptions

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *