ユーザーがボタンをクリックすると、データがテーブルに表示されるというこのプロジェクトがあります。ただし、ここで見られるようにテーブルを使用していますhttp://i.stack.imgur.com/HW4rE.jpg。私が望むのは、ユーザーが登録フォーム テーブルの追加ボタンをクリックすると、ページを更新する必要なく、追加された科目テーブルに表示されることです。問題は、テーブルを使用していて、v-model を使用して値をバインドできないことです。
だからここに私のform.blade.phpがあります
入学願書表
<table class="table table-bordered">
<tr>
<th>Section</th>
<th>Subject Code</th>
<th>Descriptive Title</th>
<th>Schedule</th>
<th>No. of Units</th>
<th>Room</th>
<th>Action</th>
</tr>
<body>
<input type="hidden" name="student_id" value="{{ $student_id }}">
@foreach($subjects as $subject)
@foreach($subject->sections as $section)
<tr>
<td>{{ $section->section_code }}</td>
<td>{{ $subject->subject_code }}</td>
<td>{{ $subject->subject_description }}</td>
<td>{{ $section->pivot->schedule }}</td>
<td>{{ $subject->units }}</td>
<td>{{ $section->pivot->room_no }}</td>
<td>
<button
v-on:click="addSubject( {{ $section->pivot->id}}, {{ $student_id}} )"
class="btn btn-xs btn-primary">Add
</button>
<button class="btn btn-xs btn-info">Edit</button>
</td>
</tr>
@endforeach
@endforeach
</body>
</table>
追加されたサブジェクト テーブル
<table class="table table-bordered">
<tr>
<th>Section Code</th>
<th>Subject Code</th>
<th>Descriptive Title</th>
<th>Schedule</th>
<th>No. of Units</th>
<th>Room</th>
<th>Action</th>
</tr>
<body>
<tr v-for="reservation in reservations">
<td>@{{ reservation.section.section_code }}</td>
<td>@{{ reservation.subject.subject_code }}</td>
<td>@{{ reservation.subject.subject_description }}</td>
<td>@{{ reservation.schedule }}</td>
<td>@{{ reservation.subject.units }}</td>
<td>@{{ reservation.room_no }}</td>
<td>
<button class="btn btn-xs btn-danger">Delete</button>
</td>
</tr>
</body>
</table>
そして、ここに私のall.jsがあります
new Vue({
el: '#app-layout',
data: {
reservations: []
},
ready: function(){
this.fetchSubjects();
},
methods:{
fetchSubjects: function(){
this.$http({
url: 'http://localhost:8000/reservation',
method: 'GET'
}).then(function (reservations){
this.$set('reservations', reservations.data);
console.log('success');
}, function (response){
console.log('failed');
});
},
addSubject: function(id,student_id){
this.$http({
url: 'http://localhost:8000/reservation',
data: { sectionSubjectId: id, studentId: student_id },
method: 'POST'
}).then(function(response) {
console.log(response);
},function (response){
console.log('failed');
});
}
}
});
ページを更新しなくても、この問題を解決する方法を教えてください。