Using the Vue created lifecycle hook

In this guide, we will be looking at Vue created lifecycle hook. In general, life cycle hooks are windows to the driving factors of our…

The post Using the Vue created lifecycle hook appeared first on CodeSource.io.


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

In this guide, we will be looking at Vue created lifecycle hook. In general, life cycle hooks are windows to the driving factors of our frameworks.

In a nutshell, they help us keep track of what happens to our components. This would usually be when they are created, updated, destroyed or before either of the listed happens.

Created lifecycle hook is a function called synchronously after the instance is created. At this point, our methods, computed properties, watch/event callbacks have all been setup.

Say we have a method or function that we need to call when the component is created, this lifecycle hook does come in handy.

<script>
export default {
  data() {
    return {
      message: "Shows a demo message",
    }
  },

  created() {
    this.displayMessage();
  },

  methods: {
    displayMessage() {
      console.log(this.message);
    },
  },
};
</script>

Basically, the method displayMessage is called when the component is created. As mentioned earlier, we have access to the data instance at this point; hence why we can make reference to the message variable in the data instance.

The post Using the Vue created lifecycle hook 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-02-17T16:09:26+00:00) Using the Vue created lifecycle hook. Retrieved from https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/

MLA
" » Using the Vue created lifecycle hook." Prince Chukwudire | Sciencx - Wednesday February 17, 2021, https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/
HARVARD
Prince Chukwudire | Sciencx Wednesday February 17, 2021 » Using the Vue created lifecycle hook., viewed ,<https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/>
VANCOUVER
Prince Chukwudire | Sciencx - » Using the Vue created lifecycle hook. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/
CHICAGO
" » Using the Vue created lifecycle hook." Prince Chukwudire | Sciencx - Accessed . https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/
IEEE
" » Using the Vue created lifecycle hook." Prince Chukwudire | Sciencx [Online]. Available: https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/. [Accessed: ]
rf:citation
» Using the Vue created lifecycle hook | Prince Chukwudire | Sciencx | https://www.scien.cx/2021/02/17/using-the-vue-created-lifecycle-hook/ |

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.