当前位置:网站首页>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
})
},
边栏推荐
猜你喜欢
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
DAY18: Xss Range Clearance Manual
文件 - 04 下载文件: 根据文件下载链接下载文件
【科普向】5G核心网架构和关键技术
【Go语言入门】一文搞懂Go语言的最新依赖管理:go mod的使用
360 push-360 push tool-360 batch push tool
Core Tower Electronics won the championship in the Wuhu Division of the 11th China Innovation and Entrepreneurship Competition
零样本学习&Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
文件 - 05 下载文件:根据文件Id下载文件
SCI写作指南
随机推荐
2022.07.12_每日一题
从 Google 离职,前Go 语言负责人跳槽小公司
Difficulty comparison between high concurrency and multithreading (easy to confuse)
Conditional statements of shell (test, if, case)
电压源的电路分析知识分享
DirectExchange交换机简单入门demo
Analysis of the principle and implementation of waterfall flow layout
服务器和客户端信息的获取
Introduction and self-order of bcos
2022.07.24_每日一题
2022.07.12 _ a day
Chapter 16: Constructing the Magic Square for Prime Numbers of Order n(5,7)
Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
gstreamer's caps event and new_segment event
tidyverse笔记——tidyr包
多进程全局变量失效、变量共享问题
Obtaining server and client information
在 ASP.NET Core 应用程序启动时运行代码的 3 种方法
2022.07.12_每日一题
单点登录 思维导图