You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
< template >
< div >
< el -upload
:action ="$http.adornUrl('/admin/file/upload/element')"
: headers = "{Authorization: $cookie.get('Authorization')}"
:on-remove ="handleRemove"
:on-success ="handleUploadSuccess"
:before-remove ="beforeRemove"
:file-list ="fileList"
multiple >
< el -button size = "small" type = "primary" > 点击上传 < / e l - b u t t o n >
< / e l - u p l o a d >
< / div >
< / template >
< script >
export default {
data ( ) {
return {
resourcesUrl : process . env . VUE _APP _RESOURCES _URL
}
} ,
props : {
value : {
default : '' ,
type : String
}
} ,
computed : {
fileList ( ) {
let res = [ ]
if ( this . value ) {
let fileArray = this . value . split ( ',' )
for ( let i = 0 ; i < fileArray . length ; i ++ ) {
res . push ( { name : fileArray [ i ] , url : this . resourcesUrl + fileArray [ i ] , response : fileArray [ i ] } )
}
}
this . $emit ( 'input' , this . value )
return res
}
} ,
methods : {
// 图片上传
handleUploadSuccess ( response , file , fileList ) {
let files = fileList . map ( file => {
return file . response
} ) . join ( ',' )
this . $emit ( 'change' , files )
} ,
// 限制图片上传大小
beforeAvatarUpload ( file ) {
const isLt2M = file . size / 1024 / 1024 < 2
if ( ! isLt2M ) {
this . $message . error ( '上传图片大小不能超过 2MB!' )
}
return isLt2M
} ,
handleRemove ( file , fileList ) {
let files = fileList . map ( file => {
return file . response
} ) . join ( ',' )
this . $emit ( 'change' , files )
} ,
beforeRemove ( file , fileList ) {
return this . $confirm ( ` 确定移除 ${ file . name } ? ` )
}
}
}
< / script >
< style lang = "scss" >
< / style >