2

My view is like this :

<table class="table table-inbox">
    ...
    <tbody>
    @foreach($messages as $message)
    <tr>
        ...
        <td>
            <div class="btn-group" role="group" aria-label="...">
                ...
                <a href="javascript:" @click="modalShow('modal-delete-message','{{ $message->id }}')" class="btn btn-danger">
                    <span class="fa fa-trash"></span> Delete
                </a>
            </div>
        </td>
    </tr>
    @endforeach
    </tbody>
</table>

@section('modal')
    <delete-message-modal id="modal-delete-message" :message-id="idModal"></delete-message-modal>
@endsection

My component vue.js (DeleteMessageModal.vue) is like this :

<template>
    <div class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                ...
            </div>
        </div>
    </div>
</template>

<script>
    export default{
        name: 'DeleteMessageModal',
        props:['messageId'],
        methods: {
            deleteMessage(event) {
                var message_id = this.messageId
                console.log(message_id)
                ...
            }
        } 
    }
</script>

When I click delete button, it will send value of message id to DeleteMessageModal component

I do : console.log(message_id), it success display value of message id

But here, I need another parameters too

The messages array on the view, besides id key, that there are seller_id key and buyer_id key

I want to send buyer_id key and seller_id key also to components vue

How can I do it?

UPDATE

My solution :

My view is like this :

<table class="table table-inbox">
    ...
    <tbody>
    @foreach($messages as $message)
    <tr>
        ...
        <td>
            <div class="btn-group" role="group" aria-label="...">
                ...
                <a href="javascript:" @click="modalShow('modal-delete-message','{{ $message->id }}#separator#{{$message->seller_id}}#separator#{{$message->buyer_id}}')" class="btn btn-danger">
                    <span class="fa fa-trash"></span> Delete
                </a>
            </div>
        </td>
    </tr>
    @endforeach
    </tbody>
</table>

@section('modal')
    <delete-message-modal id="modal-delete-message" :message-data="idModal"></delete-message-modal>
@endsection

My component vue.js (DeleteMessageModal.vue) is like this :

<template>
    <div class="modal" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                ...
            </div>
        </div>
    </div>
</template>

<script>
    export default{
        name: 'DeleteMessageModal',
        props:['messageData'],
        methods: {
            deleteMessage(event) {
                var messageData = this.messageData           
                var arr = messageData.split('#separator#')
                message_id= arr[0]
                seller_id= arr[1]
                buyer_id= arr[2]
            }
        } 
    }
</script>
2
  • Why don't you add them to the props of the component and pass it in the parent's view the same say as the messageId? Commented Mar 13, 2017 at 4:56
  • @Goliadkin, I know it. But, my problem is : how can I get value from $messages array? So, when the delete button clicked, I get value of buyer_id and seller_id Commented Mar 13, 2017 at 5:17

1 Answer 1

2

As added in comment, you can add in props:

<script>
    export default{
        name: 'DeleteMessageModal',
        props:['messageId', 'buyerId', `sellerId `],
        methods: {
            deleteMessage(event) {
                var message_id = this.messageId
                console.log(message_id)
                ...
            }
        } 
    }
</script>

and pass it in the parent template:

<delete-message-modal id="modal-delete-message" :message-id="idModal" buyer-id="123" seller-id="32"></delete-message-modal>
Sign up to request clarification or add additional context in comments.

9 Comments

I know it. But, my problem is : how can I get value from $messages array? So, when the delete button clicked, I get value of buyer_id and seller_id
@mosestoh One option can be to pass that as well as a prop or you can start thinking of using some centralised state machine as well or vuex for that matter, you can check my similar answer here.
@mosestoh Pass the values you want to modalShow function, inside of it set some variables that will be binding to DeleteMessageModal props .... and finish this one.
@Jonatas Walker, I'm still confused. You better give answer with more detailed
@Saurabh, I'm still confused. The actual core of my problem is how can I get some value from $messages array
|

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.