Commit cfdc1d79 authored by 张伯涛's avatar 张伯涛

上传限制完善

parent 0723d45d
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
<el-upload <el-upload
class="avatar-uploader" class="avatar-uploader"
action="#" action="#"
accept=".png,.jpg,.jpeg,.PNG,.JPG,.JPEG"
:http-request="handleUpload" :http-request="handleUpload"
:show-file-list="false" :show-file-list="false"
:on-success="handleAvatarSuccess" :on-success="handleAvatarSuccess"
...@@ -331,6 +331,18 @@ export default { ...@@ -331,6 +331,18 @@ export default {
}, },
beforeAvatarUpload(file) { beforeAvatarUpload(file) {
// this.file = file // this.file = file
// 判断文件是否为图片类型
const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
const isLt2M = file.size / 1024 / 1024 < 2
if (!isJPG) {
this.$message.error('只能上传图片格式的文件!')
return false
}
if (!isLt2M) {
this.$message.error('上传图片大小不能超过 2MB!')
return false
}
this.file = file
}, },
step(index) { step(index) {
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
]" ]"
> >
<el-upload <el-upload
accept=".png,.jpg,.jpeg,.PNG,.JPG,.JPEG"
class="avatar-uploader" class="avatar-uploader"
action="#" action="#"
:http-request="handleUpload" :http-request="handleUpload"
......
...@@ -165,6 +165,7 @@ ...@@ -165,6 +165,7 @@
<el-col :span="12"> <el-col :span="12">
<el-form-item label="封面:" prop="contestPicture"> <el-form-item label="封面:" prop="contestPicture">
<el-upload <el-upload
accept=".png,.jpg,.jpeg,.PNG,.JPG,.JPEG"
class="avatar-uploader" class="avatar-uploader"
action="#" action="#"
:http-request="handleUpload" :http-request="handleUpload"
......
...@@ -189,6 +189,7 @@ ...@@ -189,6 +189,7 @@
</el-form-item> </el-form-item>
<el-form-item label="图片:" prop="url"> <el-form-item label="图片:" prop="url">
<el-upload <el-upload
accept=".png,.jpg,.jpeg,.PNG,.JPG,.JPEG"
:show-file-list="false" :show-file-list="false"
list-type="picture-card" list-type="picture-card"
action="#" action="#"
......
...@@ -89,6 +89,7 @@ ...@@ -89,6 +89,7 @@
<el-col :span="8"> <el-col :span="8">
<el-form-item label="封面:"> <el-form-item label="封面:">
<el-upload <el-upload
accept=".png,.jpg,.jpeg,.PNG,.JPG,.JPEG"
:disabled="secondFromDisabled" :disabled="secondFromDisabled"
class="avatar-uploader" class="avatar-uploader"
action="#" action="#"
......
...@@ -162,6 +162,7 @@ ...@@ -162,6 +162,7 @@
v-model="form.avatarId" v-model="form.avatarId"
class="avatar-uploader" class="avatar-uploader"
action="#" action="#"
accept=".png,.jpg,.jpeg,.PNG,.JPG,.JPEG"
:show-file-list="false" :show-file-list="false"
:file-list="photoList" :file-list="photoList"
:on-change="changePhotoFile" :on-change="changePhotoFile"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment