1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

修改上传图片时只能使用默认名称的问题

上传图片时只能使用file指定的名称,而不能使用本地的文件名称
This commit is contained in:
Mrzls999 2024-01-10 15:38:46 +08:00 committed by GitHub
parent 0caa975ee2
commit 3716590b2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -225,6 +225,7 @@ export default {
} }
}, },
data() { data() {
let fileName
const { imgFormat, langType, langExt, width, height } = this const { imgFormat, langType, langExt, width, height } = this
let isSupported = true let isSupported = true
const allowImgFormat = ['jpg', 'png'] const allowImgFormat = ['jpg', 'png']
@ -478,6 +479,7 @@ export default {
}, },
// //
setSourceImg(file) { setSourceImg(file) {
this.fileName = file.name.substr(0,file.name.lastIndexOf('.'))
const fr = new FileReader() const fr = new FileReader()
fr.onload = e => { fr.onload = e => {
this.sourceImgUrl = fr.result this.sourceImgUrl = fr.result
@ -773,7 +775,8 @@ export default {
fmData.append( fmData.append(
field, field,
data2blob(createImgUrl, mime), data2blob(createImgUrl, mime),
field + '.' + imgFormat //field + '.' + imgFormat
this.fileName + '.' + imgFormat
) )
// //
if (typeof params === 'object' && params) { if (typeof params === 'object' && params) {