我正在尝试使用Ajax render()方法在laravel中渲染部分页面。部分刀片已成功加载。但是我的vue组件在部分刀片中没有被渲染。我也已经完成调试。 1.Console.log()是否在laravel中成功加载了vue组件。是的,它已成功加载。 2.安装Npm,然后运行dev运行npm。 ->仍未呈现视图,则保持不变。
索引刀片。
function loadShowPage(staff_id){
let url = '/staff/staff/' + staff_id;
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'GET',
url: url,
//data: staff_id,
dataType: 'JSON',
success: function(data)
{
if (data.status == 1){
$('#staff_modal_content').html(data.rendered);
if (!$('#staffModal').is(':visible')) {
$('#staffModal').modal('show');
}
}
else {
alert('An error has occurred. Please refresh the page and try again.');
}
},
error: function(data)
{
toggleLoader();//alert(JSON.stringify(data));
}
})
}
我的控制器
public function show(Staff $staff)
{
$user = Auth::user();
$staff->load('family_particulars');
if(!$user->can('view',$staff))
return redirect()->route('staff.staff.index');
$class = ChildClass::staffIncharge($staff->staff_id)->first();
$main_user = $staff->main_user;
$main_user->ref_user->load(['family_particulars','qualifications',
'courses','scholarship','computer_skills','previous_employment','reference','staff_employment','leaves']);
$rendered = view('staff.staff.show', ['staff'=>$staff, 'ref_user'=>$main_user,'class'=>$class])->render();
return response()->json(array('status' => 1, 'rendered' => $rendered));
//return view('staff.staff.show',['staff'=>$staff, 'ref_user'=>$main_user,'class'=>$class]);
}
show.blade.php
中的部分刀片 {!! Form::open(['id' => 'pinf-form', 'route'=> [$user->admin_type_ref_id==6? 'staff.staff.update':'staff.admin.update',$staff->staff_id] ]) !!}
@method('PUT')
@csrf
<personal-info id="personal_info_component" class="hidden" :user='{!! json_encode($user, JSON_HEX_APOS) !!}' :package='{{ GeneralHelper::getPackageId() }}'></personal-info>
{!! Form::close() !!}