[Vuejs]-How to passing props id into methods in vue js

0👍

You have 2 ways to passing data to your vue components, one is to use a static prop

<conversation_send_message_form user_id="15"></conversation_send_message_form>

and the other is to use dynamic properties

<conversation_send_message_form v-bind:user_id="user.id"></conversation_send_message_form>

Be aware of laravel blade vs mustache-like syntax

those properties are being received in component with "props", and accesible inside js with this.PROPNAME (and accesible inside template with PROPNAME directly) So your only problem is name mismatch, just change

export default {
    props: ['userId'],
    send() {
            this.sendMessage({
                recipientIds: this.userId,
                body: this.body
            }).then(() =>{
                this.recipients= []
                this.body = null
            })
     },
}

Be also aware of naming with camelCase vs kebab-case: https://v2.vuejs.org/v2/guide/components.html#camelCase-vs-kebab-case

Leave a comment