知识点:
<1>.a的download 属性规定被下载的超链接目标,download属性可以设置一个值来规定下载文件的名称,(.img, .pdf, .txt, .html, 等等)。
<2>.a标签可以作为下载链接,做为超链接下载的目标时必须要有href属性。
<3>.h5中的Blob()对象,Blob本身没有什么,但是可以用于二进制数据的大理JS api提供重要的数据交换机制。
function saveContent (content, fileName) {
let aTag = document.createElement('a');
aTag.setAttribute('download',fileName);
let blob = new Blob([content],{type:""});
aTag.setAttribute('href',URL.createObjectURL(blob));
document.body.appendChild(aTag);
aTag.click();
document.body.removeChild(aTag);
}
let json={
name: "tutu",
age: "18",
sex: "man",
};
saveContent(JSON.stringify(json),"test.pipeline");