当前位置:网站首页>van-uploader uploads images, and cannot preview the image using base64 echo
van-uploader uploads images, and cannot preview the image using base64 echo
2022-07-31 07:40:00 【puppet running】
1.今天在开发过程中,遇到了使用vant上传组件,The echo cannot be previewed,在搜索后,解决方法如下:
- html:
<van-uploader v-model="fileList"
accept='.jpg,.jpeg,.png'
:before-read="beforeRead"
:after-read="afterRead"
:max-size="10000 * 1024"
@oversize="onOversize"
:before-delete="beforeDel" />
- js
fileNameList.split(',').forEach(v => {
// Iterate over the filenames returned by the backend
this.$http.secondParty.getImageByName({
fileName: v }).then(k => {
// filename request tobase64格式文件
// 图片base64转url
let img = 'data:image/jpeg;base64,' + k.data
let imgurl = this.base64ImgtoFile(img)
console.log('imgurl===', imgurl)
let url =
window.webkitURL.createObjectURL(imgurl) ||
window.URL.createObjectURL(imgurl)
// 创建图片地址
this.fileList.push({
content: 'data:image/jpeg;base64,' + k.data,
File: imgurl,
name: v,
status: 'done',
message: '上传中',
isImage: true,
url
})
})
})
- base64转文件
base64ImgtoFile(dataurl, filename = 'file') {
const arr = dataurl.split(',')
const mime = arr[0].match(/:(.*?);/)[1]
const suffix = mime.split('/')[1]
const bstr = atob(arr[1])
let n = bstr.length
const u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new File([u8arr], `${
filename}.${
suffix}`, {
type: mime
})
},
边栏推荐
- 360推送-360推送工具-360批量推送工具
- DAY18: XSS vulnerability
- Explain the example + detail the difference between @Resource and @Autowired annotations (the most complete in the entire network)
- 单点登录 思维导图
- Difficulty comparison between high concurrency and multithreading (easy to confuse)
- [PSQL] SQL基础教程读书笔记(Chapter1-4)
- 2022.07.14_每日一题
- 【Go语言入门教程】Go语言简介
- 任务及任务切换
- 完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
猜你喜欢

小实战项目之——吃货联盟订餐系统

芯塔电子斩获第十一届中国双创大赛芜湖赛区桂冠
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?

2022.07.13_每日一题

2022.07.18 _ a day

英语翻译软件-批量自动免费翻译软件支持三方接口翻译

双倍数据速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM)- 逻辑描述部分

LeetCode:952. 按公因数计算最大组件大小【欧拉筛 + 并查集】

Redux state management

任务及任务切换
随机推荐
codec2 BlockPool:不可读库
庐山谣寄卢侍御虚舟
DAY18: Xss Range Clearance Manual
【解决】mysql本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止
Explain the example + detail the difference between @Resource and @Autowired annotations (the most complete in the entire network)
2022.07.14_Daily Question
360 push-360 push tool-360 batch push tool
nohup principle
[PSQL] SQL基础教程读书笔记(Chapter1-4)
Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
Conditional statements of shell (test, if, case)
04-SDRAM:读操作(突发)
项目 - 如何根据最近30天、最近14天、最近7天、最近24小时、自定义时间范围查询MySQL中的数据?
【C语言项目合集】这十个入门必备练手项目,让C语言对你来说不再难学!
把 VS Code 当游戏机
基于LSTM的诗词生成
【科普向】5G核心网架构和关键技术
小实战项目之——吃货联盟订餐系统
Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software