Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

416
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda