Home » vue » Mounted method called twice when used component in page

Mounted method called twice when used component in page

Posted by: admin November 26, 2021 Leave a comment

Questions:

I have a modal code in one component which i am using in the page, everything works fine but if I refresh the page than mounted hook called twice which is breaking my code. I want it to called only once.

import axios from '~/plugins/axios';

export default {
  data() {
    return {}
    };
  },
  components: {
    LoginSignupModal
  },
  mounted() {
    console.log('mounted called......');
  },
<template>
    <div>
      <p>
        <LoginSignupModal :isModalOpen='isModalOpen' v-on:onModalClose="onModalClose($event)"></LoginSignupModal>
      </p>
    </div>
</template>

Answers:

You cannot paste div into paragraph.

Remove <p> and it should work.