Reputation: 13172
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>
Upvotes: 2
Views: 5085
Reputation: 73609
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>
Upvotes: 2