1

I'm building a chat app, and in the cat vue component I have:

<template>
<div class="chat-app">
    <Conversation :contact="selectedContact" :messages="messages" @new="saveNewMessage"/>
    <ContactsList :contacts="contacts" @selected="startConversationWith"/>
</div>

then in the script part, in the methods array, I have:

saveNewMessage(message) {
            this.messages.push(message);
        },

Basically, there is an attribute in contact that I want to bring into the message to save it in message - the conversation_id. Is there a way to get contact into saveNewMessage()? I tried saveNewMessage(message, contact), but that didn't work. Thanks in advance!

1 Answer 1

1

You have access to all the data properties in the your component methods:

saveNewMessage(message) {
  // access the selected contact
  this.selectedContact

  ...

  this.messages.push(message);
},
Sign up to request clarification or add additional context in comments.

3 Comments

I tried to console.log(this.selectedContact) and I got undefined.
How are you assigning the selectedContact property?
I ate dinner and refreshed the page, and it worked! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.