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

256
Visualizações
Vue event bus emit object not passed to component

I'm emitting an object via event bus to the parent and then assigning that object to my detail variable which is to be passed as a prop to my ContactDetail component, but the prop isn't getting the updated object.

ContactCard is a component imported in ContactList.

Getting the following error:

[Vue warn]: Property or method "contactDetail" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

ContactCard

<script>
import {bus} from "../../bus.js";

export default {
    name: "ContactCard",
    methods: {
        showDetails: function(event) {
            bus.$emit('showDetails', { pfp: this.pfp, name: this.name, address: this.address });
        }
    }
}
</script>

AddressBook

<template>
    <div class="container">
        <ContactList v-if="!showDetail"></ContactList>
        <ContactDetail v-else :contactDetail="details"></ContactDetail>
    </div>
</template>

<script>
import { bus } from "../bus.js";
import ContactList from "../components/addressBook/ContactList.vue";
import ContactDetail from "../components/addressBook/ContactDetail.vue";

export default {
    name: "AddressBook",
    components: {
        ContactList,
        ContactDetail
    },
    data() {
        return {
            showDetail: false,
            details: {}
        }
    },
    created() {
        bus.$on('showDetails', (data) => {
            console.log(data);
            this.showDetail = true;
            this.details = Object.assign({}, this.details, data);
            console.log(this.details);
        });
    }
}
</script>

ContactDetail

<template>
    <div class="detail-container">
        {{contactDetail}}
    </div>
</template>

<script>
export default {
    name: "ContactDetail",
    data() {``
        return {
            details: ''
        }
    },
    props: {
        contactDetail: {
            type: Object,
            required: true
        }
    },
    watch: {
        contactDetail(newVal, prevVal) {
            this.details = newVal;
        }
    }
}
</script>

Why isn't the contactDetails prop updated in ContactDetail?

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

0

Accidentally had two script sections instead of script and style.

Before

<template>
    <div class="detail-container">
        {{details}}
    </div>
</template>

<script>
import { bus } from "../../bus.js";
export default {
    name: "ContactDetail",
    data() {
        return {
        }
    },
    props: {
        details: {
            type: String,
            required: true
        }
    }
}
</script>

<script>
</script>

After

<template>
    <div class="detail-container">
        hellow
        {{details}}
    </div>
</template>

<script>
import { bus } from "../../bus.js";
export default {
    name: "ContactDetail",
    data() {
        return {
            pfp: "",
            name: "",
            address: ""
        }
    },
    props: {
        details: {
            type: String,
            required: true
        }
    }
}
</script>

<style>
</style>
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