I have a button that, when clicked, triggers a modal to open. The content displayed in the modal is determined by the data attributes passed to the button.
Here is my button:
<button class="btn btn-info" data-toggle="modal"
data-target="#someModal" :data-id=item.id :data-name=item.name>
Edit
</button>
Within the modal, there are buttons that, when clicked, should execute a vuejs function with a parameter based on the data attribute.
Modal button code:
<div class="modal-footer">
<button type="button" class="btn btn-danger"
@click.prevent="deleteItem()" data-dismiss="modal">
Delete
</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">
<span class='glyphicon glyphicon-remove'></span> Close
</button>
</div>
In this scenario, a parameter needs to be passed to the deleteItem()
function, which corresponds to the data-id
obtained from the preceding button.
Modal Code:
<div id="deleteModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Delete</h4>
</div>
<div class="modal-body">
<div class="deleteContent">
Are you sure you want to delete?
</div>
<div class="modal-footer">
<button type="button" class="btn actionBtn btn-danger"
@click.prevent="deleteItem()"
data-dismiss="modal">
Delete <span id="footer_action_button"
class='glyphicon glyphicon-trash'> </span>
</button>
<button type="button" class="btn btn-warning"
data-dismiss="modal">
<span class='glyphicon glyphicon-remove'></span> Close
</button>
</div>
</div>
</div>
</div>
</div>