blob 转file及下载

1. blob转file

 blobToFile (theBlob) {
      let file = new window.File([theBlob], '文件名字', {type: 'image/jpeg'})
 }

2. dataUrl转blob

this.$refs['当前图片定义的ref'].toBlob(blob => {
        let a = document.createElement('a')
        document.body.appendChild(a)
        a.style = 'display: none'
        this.blobUrl = window.URL.createObjectURL(blob)
        a.href = this.blobUrl
        a.download = this.url
        a.click()
        document.body.removeChild(a)
        window.URL.revokeObjectURL(this.blobUrl) // 下载图片
      }, 'image/jpeg')
原文地址:https://www.cnblogs.com/xx929/p/11903611.html