最近项目有个需求需要在前端vue上传图片,然后在后端将图片存到本地的一个文件夹下。
1、vue
这里是将上传图片封装成了一个组件来使用,组件名为 upload-image.vue
<template>
<div class="clearfix">
<!--
name —— 向后端传递数据时会要用到
action —— 后端路径
-->
<a-upload
name="faceImage"
:headers="headers"
:action="fileurl"
list-type="picture-card"
v-model:file-list="fileList"
:before-upload="beforeUpload"
@preview="handlePreview"
@change="handleChange"
>
<div v-if="fileList.length < imgNum">
<a-icon type="plus" />
<div class="ant-upload-text">
上传图片
</div>
</div>
</a-upload>
<a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
<img alt="example" style="width: 100%" :src="previewImage" />
</a-modal>
</div>
</template>
<sc

最低0.47元/天 解锁文章
3271

被折叠的 条评论
为什么被折叠?



