赞
踩
},
computed: {
imageUrl() {
return this.value
},
imageName() {
if (this.value != null && this.value !== ‘’) {
return this.value.substr(this.value.lastIndexOf(‘/’) + 1)
} else {
return null
}
},
fileList() {
return [{
name: this.imageName,
url: this.imageUrl
}]
},
showFileList: {
get: function() {
return this.value !== null && this.value !== ‘’ && this.value !== undefined
},
set: function(newValue) {
}
}
},
methods: {
emitInput(val) {
this.$emit(‘input’, val)
},
handleRemove(file, fileList) {
this.emitInput(‘’)
},
handlePreview(file) {
this.dialogVisible = true
},
getUUID() {
return ‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx’.replace(/[xy]/g, c => {
return (c === ‘x’ ? (Math.random() * 16 | 0) : (‘r&0x3’ | ‘0x8’)).toString(16)
})
},
beforeUpload(file) {
const _self = this
return new Promise((resolve, reject) => {
// 前后端提交post异步请求获取签名信息
this.postRequest(‘/oss/policy’)
.then((response) => {
_self.dataObj.policy = response.policy
_self.dataObj.signature = response.signature
_self.dataObj.ossaccessKeyId = response.accessid
self.dataObj.key = response.dir + this.getUUID() + '${filename}’
_self.dataObj.dir = response.dir
_self.dataObj.host = response.host
resolve(true)
}).catch(err => {
reject(false)
})
})
},
handleUploadSuccess(res, file) {
console.log(‘上传成功…’)
this.showFileList = true
this.fileList.pop()
this.fileList.push({ name: file.name, url: this.dataObj.host + ‘/’ + this.dataObj.key.replace(‘${filename}’, file.name) })
this.emitInput(this.fileList[0].url)
}
}
}
引用上传子组件的页面的示例代码:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。