FileReader

https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader

FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据

  if (res.type === 'application/json' || res.type === 'application/json;charset=UTF-8') {
    let fileReader = new FileReader()
    fileReader.onload = function(event) {
      // console.log(event)  // 
      let jsonData = JSON.parse(this.result) // this.result是根据event,读取文件后打印的
      console.log(jsonData, '...............')
      if (jsonData.data === null && jsonData.code === 1) {
        Message({
          message: jsonData.msg || 'Error',
          type: 'error',
          duration: 5 * 1000
        })
      }
    }
    fileReader.readAsText(res)
  }
原文地址:https://www.cnblogs.com/shun1015/p/13254584.html