画布图片预览
This commit is contained in:
@@ -2,4 +2,17 @@ export const createId = (before: string = 'node') => {
|
||||
const time = Date.now().toString(36)
|
||||
const random = Math.random().toString(36).substring(2, 20)
|
||||
return `${before}_${time}${random}`
|
||||
}
|
||||
|
||||
/** 下载图片 */
|
||||
export const downloadImage = (url: string, name: string) => {
|
||||
fetch(url)
|
||||
.then((res) => res.blob())
|
||||
.then((blob) => {
|
||||
const a = document.createElement('a')
|
||||
a.href = URL.createObjectURL(blob)
|
||||
a.target = '_blank'
|
||||
a.download = name || 'image.png'
|
||||
a.click()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user