关于javascript:下载txt文档

59次阅读

共计 395 个字符,预计需要花费 1 分钟才能阅读完成。

  // 下载 txt 文档
    downloadTxtFile = async () => {
        const content = await axios({
            method: "GET",
            url: downloadTempUlr,
        });
        const aLabel = document.createElement("a");
        const labelEvent = document.createEvent("MouseEvents");
        labelEvent.initEvent("click", false, false);
        aLabel.href ="data:text/plain;charset=utf-8," + encodeURIComponent(content.data);
        aLabel.download = dowmloadName;
        aLabel.target = "_blank";
        aLabel.dispatchEvent(labelEvent);
    };

正文完
 0