IonViewDidEnter not working

I am trying to use ionic lifecycle hook ionViewDidEnter() . but it is giving error

   59:5  error  'ionViewDidEnter' is not defined  no-undef

that’s how I am trying

 setup() {
    ionViewDidEnter(() => {
      console.log('Home page did enter');
    });

      const router = useRouter();
      return { router };
    },

I think you’re meaning to use onIonViewDidEnter

here is my whole component

<template>
  <ion-page>
    <ion-header>
      <ion-toolbar>
        <ion-title>My Wrokers</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content :fullscreen="true">
      <ion-header collapse="condense">
        <ion-toolbar>
          <ion-title size="large">My Workers</ion-title>
        </ion-toolbar>
      </ion-header>
      <ion-list>
    <ion-item v-for="(worker, index) in this.workers" :key="index" @click="() => router.push(`/staff/${worker.id}/worker`)">
      <ion-label
        text-wrap>{{ worker.id }} - {{ worker.name }}
      </ion-label>
    </ion-item>
  </ion-list>
    </ion-content>
  </ion-page>
</template>

<script >
import {
  IonPage,
  IonHeader,
  IonToolbar,
  IonTitle,
  IonContent,
   IonItem, IonList, IonLabel,
  onIonViewWillEnter,
} from "@ionic/vue";
import { TokenService } from '@/services/token.service';
import ApiService from '@/services/api.service';
import { useRouter } from 'vue-router';
export default {
  name: "Tab2",
  data() {
    return {
      workers: "",
    };
  },
  components: { IonHeader, IonToolbar, IonTitle, IonContent, IonPage, IonItem, IonList, IonLabel, },
  methods: {
    getBossWorkers: function () {
      const boss_id = TokenService.getUserInfo().id;

      return ApiService.get(`/api/gangBoss/get-boss-workers/${boss_id}`).then(
        (response) => {
          this.workers = response.data;

        }
      );
    },
  },
  setup() {

 onIonViewWillEnter(() => {
    console.log('Entered tab!');
  });
      const router = useRouter();
      return { router };
    },
  mounted() {

    this.getBossWorkers();
  },

};
</script>
<style scoped>
ion-list ion-item {
  background-color: #F0F8FF;

    /* margin-top: 7px; */
  margin-bottom: 0px;
}
</style>

yes write i changes it and also import it now i am receiving new error

"export 'onIonViewWillEnter' was not found in '@ionic/vue'

Make sure you are on the latest ionic/vue release

its version 5.4.0 , how i can upgrade it. i tried npm i

Thanks sir i updated it to 5.6.0 and its working

1 Like