当前位置:   article > 正文

vue + element-ui + 阿里云oss服务端签名后直传实践_vue事现客户端oss签名直传

vue事现客户端oss签名直传

},

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)

}

}

}

引用上传子组件的页面的示例代码:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/703006
推荐阅读
相关标签
  

闽ICP备14008679号