<template>
<el-upload
class="avatar-uploader"
:http-request="httpRequest"
:action="actionUrl"
name='bankimg'
:show-file-list="false">
<img v-if="ruleForm.bankimg" :src="ruleForm.bankimg" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
</el-upload>
</template>
<script>
export default {
data() {
return {
actionUrl:''翔曲,
ruleForm:{
bankimg:'',
}
}
methods: {
httpRequest (options) {
let file = options.file
let filename = options.filename
if (file) {
this.fileReader.readAsDataURL(file)
}
this.fileReader.onload = () => {
let base64Str = this.fileReader.result.split(',')[1]
this.$axios.post("/payways/upload",{file:base64Str})
.then(res => {
if(filename=='bankimg'){
this.ruleForm.bankimg= res.data.biz_response.data
}
console.log(res)
})
.catch(err => {
console.log(err)
})
}
},
}
}
</script>
el_upload組件自定義上傳轉(zhuǎn)為base64編碼的圖片