<el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList"> <el-button size="small" type="primary">点击上传</el-button> <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div></el-upload><script> export default { data() { return { fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}] }; }, methods: { handleRemove(file, fileList) { console.log(file, fileList); }, handlePreview(file) { console.log(file); } } }</script>上面是element-ui的官方组件
1 回答
慕侠2389804
TA贡献1719条经验 获得超6个赞
看了一下源码,file 里有个属性 raw , 其实就是rawFile
把钩子挂在preview 上为例:
previewBanner(file){
let reader = new FileReader()
reader.onload = () => {
let _base64 = reader.result
doWhatUWant(_base64)//就可以做你想做的啦!!!
}
reader.readAsDataURL(file.raw)
}
添加回答
举报
0/150
提交
取消