保存文件为txt,浏览器下载到本地。使用Blob对象



const data = "内容" // 这里填内容的字符串
const blob = new Blob([data], { type: "text/plain" })
const a = document.createElement("a")
a.href = URL.createObjectURL(blob)
a.download = "fileName.txt" // 这里填保存成的文件名
a.click()
URL.revokeObjectURL(a.href)
a.remove();