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

122
Visualizações
Vue: TypeError: Cannot read properties of undefined (reading 'title') on page reload

I have a pretty common issue accessing data while the page is loading, however, I cannot figure this out.

My code is as follows:

    computed: {

       nowPlaying() {
               if(this.$store.state.radio && !this.loading) {
            
        let meta = Object.values(this.apollo).filter(el => el.channel === this.activeChannel)
          this.title = meta[0].title,
          this.artist = meta[0].artist
            }  
        },

Hot reload works as expected but page reload returns an undefined error for both title & artist:

TypeError: Cannot read properties of undefined (reading 'title') at VueComponent.nowPlaying (Player.vue?7cf3:45:1)

This happens only if I try to access an element in the meta array using [].

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looks like on page load, this.apollo or this.activeChannel not available as computed property always call prior to mounted() hook.

Can you please ensure that this.apollo and this.activeChannel is available in mounted() or data property.

Demo how it works :

new Vue({
  el: '#app',
  data() {
    return {
      property: 'Example property'
    }
  },
  computed: {
    propertyComputed() {
      console.log('computed'); // Called first on page load
    }
  },
  mounted() {
    console.log('mounted');
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div>{{ propertyComputed }}</div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
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