思路很简单,就是利用Blob、URL.createObjectURL()方法和<a> 便签的HTML5新属性download来模拟远端文件下载保存。下面直接上代码

savePath: function(){
      var me = this;
      if(!me.curve){
        $.uitools.alertDlg("Path还没有定义,请先定义路径!");
        return;
      }
      var json = me.pathToJson();
      var blob = new Blob([json]);
      var url =  URL.createObjectURL(blob);
      var a = document.createElement("a");
      a.setAttribute('download','path.json');
      a.setAttribute('href',url);
      document.body.appendChild(a);
      a.click();
      a.remove();
    },

 

版权声明:本文为我看青山多妩媚原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/dajianshi/p/16771836.html