Is there a way to break or exit out of the mounted hook cycle in vue.js after a specific operation/task is done?

Viewed 3827

I am currently working on a project related to vuex. In order to launch the website, I want to trigger a function without creating a button in the html part of the vue file. I used mounted hook life cycle to call the javascript function, but I want to break out of the mounted lifecycle after a specific operation is done. Is it possible to break out of a mounted lifecycle once a certain operation is done? If yes, how do we do it?

1 Answers

You should just be able to use return.

Example:

mounted() {
  console.log(`Now you see me`);
  return;
  console.log(`Now you don't`);
}

Only the first console.log will be executed, return will exit you from the function.

Related