微信公众号用vue开发,需要下载功能?
微信公众号用vue开发,用到下载功能,在公众号里面点击下载时提示“可在浏览器打开次网页来下载文件”,但在google浏览器点击下载可以自动下载。以下是所用代码,请问下有什么问题或者提供下其他方法,谢谢。 export function downloadPicture(imgSrc, name) { const image = new Image() // 解决跨域 Canvas 污染问题 image.setAttribute('crossOrigin', 'Anonymous') image.src = imgSrc image.onload = () => { const canvas = document.createElement('canvas') canvas.width = image.width canvas.height = image.height const context = canvas.getContext('2d') context.drawImage(image, 0, 0, image.width, image.height) canvas.toBlob((blob) => { const url = URL.createObjectURL(blob) const eleLink = document.createElement('a') eleLink.download = name || 'photo' eleLink.href = url eleLink.click() eleLink.remove() URL.revokeObjectURL(url) }) } }