Tôi có một bảng đơn giản mà sẽ hiển thị tất cả các dữ liệu của tôi:Đi qua một biến để một thành phần Vue từ trang mẹ mà gọi nó là
chính file.php
<table class="table table-bordered table-hover" id="all-jobs">
<thead>
<tr>
<th>{{ __('Job Name') }}</th>
<th>{{ __('Job Description') }}</th>
<th>{{ __('Job Status') }}</th>
<th>{{ __('Job Applications') }}</th>
<th>{{ __('Manage') }}</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td class="non_searchable"></td>
<td class="non_searchable"></td>
</tr>
</thead>
</table>
<div id="app">
<div id="editJob" class="modal fade in" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<edit-job id=""></edit-job>
</div>
</div>
</div>
</div>
Bây giờ, tôi có nút chỉnh sửa mà tôi đang cố mở một phương thức chỉnh sửa cho hàng cụ thể đó:
<a href='' data-id='{$job->id}' class='btn btn-xs btn-danger' data-toggle='modal' data-target='#editJob'><i class='fa fa-close'></i></a>";
href là vị trí trong một trong bảng dữ liệu của tôi, tôi đang cố gắng ss đó để tập .vue của tôi để tôi có thể sử dụng nó cho GET và POST yêu cầu của tôi:
myfile.vue
<template>
<div>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit Job</h4>
</div>
<div class="modal-body">
<form method="post" @submit.prevent="signIn" @keydown="errors.clear($event.target.name)">
<!-- Removed code, it's just inputs !-->
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info btn-fill btn-wd" v-on:click="addJob">Save</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</template>
<script>
export default
{
props: ['id'],
data: function()
{
return {
countries: [],
name: '',
summary: '',
salarytype: '',
salaryfrom: '',
salaryto: '',
location: '',
contactemail: '',
contactphone: '',
errors: new Errors()
}
},
methods:
{
addJob: function()
{
axios.post('/jobs/edit', this.$data)
.then(response => {
if(response.data.status === true){
$('#editJob').modal('hide');
getJobTable();
}
else{
formError = response.data.message;
}
})
.catch(error => this.errors.record(error.data))
}
},
mounted: function()
{
console.log($(this).data('id'));
axios.get('/jobs/my-job/')
.then(response => {
this.name = response.data.name
this.summary = response.data.summary
this.salarytype = response.data.salary_type
this.salaryfrom = response.data.salary_from
this.salaryto = response.data.salary_to
this.location = response.data.location
this.contactemail = response.data.contact
this.contactphone = response.data.phone
})
axios.get('/countries')
.then(response => {
this.countries = response.data;
})
}
}
</script>
Làm thế nào tôi có thể qua id href của tôi để tôi sử dụng cho yêu cầu của tôi? Cảm ơn
cấu trúc MY:
Created-jobs.blade.php
Sửa-Job.vue
app.js
Bảng chỉ populates dữ liệu, và cho biết thêm menu thả xuống như vậy:
<ul class='icons-list'>
<li class='dropdown'>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
<i class='icon-menu9'></i>
</a>
<ul class='dropdown-menu dropdown-menu-right'>
<li>
<a data-id='{$job->id}' onclick='getID({$job->id})' data-toggle='modal' data-target='#editJob'>
<i class='icon-file-pdf'></i> Edit Job
</a>
</li>
<li>
<a href='javascript:void();' data-id='{$job->id}' onclick='deleteJob({$job->id})'>
<i class='icon-cross'></i> Delete Job
</a>
</li>
</ul>
</li>
</ul>
Hãy nhìn vào documenation [vueDoc Props] (https://vuejs.org/v2/guide/components.html#Props) hoặc nếu bạn muốn có toàn bộ mã trong phụ huynh, bạn có thể sử dụng [vueDoc Slots] (https://vuejs.org/v2/guide/components.html#Named-Slots) –
Reiner
Tôi đã xem tài liệu về đạo cụ nhưng không thể thấy bất kỳ điều gì với việc chuyển id từ href to the prop :( –
Chỉ cần sử dụng một vị trí trong thẻ thành phần như trong ví dụ này https://vuejs.org/v2/examples/modal.html bạn có thể xác định mọi thứ trong mẫu chính nhưng vị trí sẽ được hiển thị trong – Reiner