js Blob对象实现文件下载功能,可以将字符串放到文件夹里,提供下载功能。
//下载功能
$("#download").click(function () {
const data = result // 这里填内容的字符串
const blob = new Blob([data], {type: "text/plain"})
const link = document.createElement("a")
link.href = URL.createObjectURL(blob)
link.download = "test.json" // 这里填保存成的文件名
link.click()
URL.revokeObjectURL(link.href)
})
注意:
1.data放的字符串
2.文件名可以自定义,改成test.txt则是txt文件,意思是可以自定义文件类型。