【发布时间】:2020-10-08 18:42:21
【问题描述】:
我正在使用 Dropzone 使用 vue.js 在 SPA 中上传图像,虽然路径正确但图像不出现不知道为什么! enter image description here vue开发工具截图
我使用的代码
<img
:src="imageObject.data.attributes.path"
:class="classes"
ref="userImage"
:alt="alt"
>
和控制器中的代码
$data = request()->validate([
'image' => '',
'width' => '',
'height' => '',
'location' => ''
]);
$image = $data['image']->store('user-images', 'public');
$userImage = auth()->user()->images()->create([
'path' => $image,
'width' => $data['width'],
'height' => $data['height'],
'location' => $data['location'],
]);
return new UserImageResource($userImage);
在我使用的 User.php 模型中
public function coverImage()
{
return $this->hasOne(UserImage::class)
->orderByDesc('id')
->where('location', 'cover')
->withDefault(function ($userImage) {
$userImage->path = 'user-images/cover-default-image.png';
});
}
与 profileImage 方法相同 和资源
return [
'data' => [
'type' => 'user-images',
'user-image-id' => $this->id,
'attributes' => [
'path' => url($this->path),
'width' => $this->width,
'height' => $this->height,
'location' => $this->location,
]
],
'links' => [
'self' => url('/users/'.$this->user_id)
]
];
【问题讨论】:
标签: laravel vue.js single-page-application dropzone.js laravel-mix