作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的观点是这样的:
<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
我的组件 vue.js (DeleteMessageModal.vue) 是这样的:
<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>
当我点击删除按钮时,它会将消息id的值发送给DeleteMessageModal组件
我这样做:console.log(message_id)
,它成功显示消息 id 的值
但是在这里,我还需要另一个参数
view上的messages数组,除了id key,还有seller_id key和buyer_id key
我也想将 buyer_id 键和 seller_id 键发送到组件 vue
我该怎么做?
更新
我的解决方案:
我的观点是这样的:
<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
我的组件 vue.js (DeleteMessageModal.vue) 是这样的:
<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>
最佳答案
如在评论中添加,您可以在 Prop 中添加:
<script>
export default{
name: 'DeleteMessageModal',
props:['messageId', 'buyerId', `sellerId `],
methods: {
deleteMessage(event) {
var message_id = this.messageId
console.log(message_id)
...
}
}
}
</script>
并将其传递到父模板中:
<delete-message-modal id="modal-delete-message" :message-id="idModal" buyer-id="123" seller-id="32"></delete-message-modal>
关于javascript - 如何向组件 vue.js 发送两个或多个参数? (vue.js 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42756481/
我是一名优秀的程序员,十分优秀!