var hiddenElement = document.getElementById('download_a');
hiddenElement.href = "data:text/csv;charset=utf-8," + encodeURI(csvContent);
hiddenElement.target = '_blank';
hiddenElement.download = "CRS_Export_" + this.getDateStr() + ".csv";
console.log("ready to go ..");
hiddenElement.click();
核心逻辑就是用<a>标签通过上述方式操作一下。
其中,“document.getElementById('download_a');”我还担心不能用,后来发现这种担心是多余的。
几年前我记得lightning component里面这种全局对象都被封装屏蔽掉了不能随便用...
顺便发点牢骚,lightning component对开发者非常不友好,干点啥事都好吃力。今天我在开发的时候就是一直在心里问候aura框架作者的祖宗多少代。