base64转二进制

methods:{
  dataURLtoFile(baseurl) { let arr
= baseurl.split(","), mime = arr[0].match(/:(.*?);/)[1], bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); while (n--) {   u8arr[n] = bstr.charCodeAt(n); } return new Blob([u8arr], {   type: mime, }); },   scan() {     let baseImg = 'data:image/png;base64,/9j/4AAQSkZJRgABAQEA3QDdAAD...'     let file = this.dataURLtoFile(baseImg ); const formData = new FormData(); formData.append("file", file, "image.png"); this.$post("接口路径", formData, { headers: { "Content-Type": "multipart/form-data", }, }).then((res) => {     调取成功     })   }
}
 

 

posted @ 2024-01-06 17:49  挽你手  阅读(147)  评论(0编辑  收藏  举报