Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

413
Vistas
VueJS component's Created()/Mounted() event is getting called while leaving the component

I have an AngularJS application where I'm using few components of Vue (version 2).

The Navigation bar of the app is in AngularJS.

When I switch between different navigation options (Home/Support), I'm loading the related Vue components.

VueJS project is built using npm run buid-lib and linked in angularJS app (npm link). Library name is myVueApp.

Using ngVue library to integrate Vue with AngularJS.

Code to load Vue Components in AngularJS app (as plugin):

(function() {
'use strict';

if (typeof myVueApp !== 'undefined') {
    var VueContainer = myVueApp.components.VueContainer,
        plugins = myVueApp.plugins;
}

angular
    .module('my.vue.config', ['ngVue', 'ngVue.plugins'])
    .config(function($ngVueProvider) {
        $ngVueProvider.setRootVueInstanceProps(plugins);
    })

    // Add Vue components here
    .value('VueContainer', VueContainer);
})();

In HTML page, I'm loading the component like below example:

Home.Html (In AngularJS)

<div>
     <vue-component name="VueContainer"></vue-component>
</div>

Routing of the Vue Components in Angular Controller:

var ngModule = angular.module('home.content', ['ui.router']);
ngModule.config(function ($stateProvider) {
$stateProvider
  .state('home.content', {
    url: '?home&t',
    controller: 'HomeCtrl as HomeCtrl ',
    templateUrl: '/views/home.html',
    resolve: {
     
    },
    onEnter: function(){

    }
});

When I switch between Vue Components, the Created/Mounted event of the each Vue component (callee and called) is getting called.

Example Vue Components:

HomeComponent.Vue

  async created() { //This is called every time it is switched to other component
       await this.getHomeData();
       this.loading = false;
}

SupportComponent.Vue

  created() { //This is called every time it is switched to other component
      this.$store.dispatch('getAllSupportProp');
      this.loadDetails();
}

In angular app, when I swtich from HomeComponent.Vue to SupportComponent.Vue or vice-versa, created/mounted events of both the components are getting called while it should only call the target component's created event.

When I run the Vue app alone (not with AngularJS), the switching between components doesn't have this problem (Callee component doesn't get called).

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda