我从API控制器获取数据。
这是我的API路由
Route::middleware('auth:api')->get('/{electionId}/form/image/d/{wilayahId}', 'Api\FormDController@getImageAtWilayah');
这是我的API控制器
public function getImageAtWilayah($electionId, $wilayahId)
{
$result = FormDImageDetail::with('formd_image')
->where('jenis_pemilihan', $electionId)
->where('id_wilayah', $wilayahId)
->where('versi', function($query) use($electionId) {
$query->select(DB::raw('max(versi)'))
->from('formd_image')
->whereColumn('id_wilayah', 'formd_image_detail.id_wilayah')
->where('flag_aktif', true)
->where('jenis_pemilihan', $electionId);
});
return $result;
}
这是我的Vue Js模板
<template>
<div>
<div id="imageScroll">
<ul>
<li v-for="items in formd" id="listForm">
<img :src="'/storage/image/formc/'+items.form_image" class="view-form-d-image"/>
</li>
</ul>
</div>
</div>
</template>
还有这个Vue Js方法来获取API
methods:{
getResult(url){
eventBus.$on("wilayah-change", (wilayahId) => {
url = "/api/" + this.electionId + "/form/image/d/" + wilayahId;
axios.get(url)
.then((response) => {
if (response.data) {
this.formd = response.data.data;
this.makePagination(response.data);
}
});
});
如何使图像无法从目录URL访问。我要确保它是私人访问。