vue下载文件

this.$api.get('url', null, r => {
  var blob = new Blob([JSON.stringify(r)],
    {type : 'application/json'});
  var url = URL.createObjectURL(blob);
  if (window.navigator.msSaveOrOpenBlob) {
    navigator.msSaveBlob(blob, row)
  } else {
    var link = document.createElement('a')
    link.href = window.URL.createObjectURL(blob)
    link.download = row
    link.click()
    //释放内存
    window.URL.revokeObjectURL(link.href)
  }
 }, fail => {
   this.$message.error('获取地址失败');
 });

你可能感兴趣的:(vue)