1. 程式人生 > 其它 >實現檔案開啟新頁面預覽

實現檔案開啟新頁面預覽

技術標籤:上傳下載

要求通過地址獲取檔案流 但是我這邊需要在header中帶token 所以 直接訪問window.open(url)地址報沒有許可權

所以通過訪問介面地址返回檔案流通過流檔案建立檔案物件展示在新的視窗。

      handlePreview (file) {
        const _this = this
        _this.$http({
          url: _this.$http.adornUrl('file/' + file.url),
          method: 'get',
          responseType: 'blob',
        }).then(({ data }) => {
          window.open(window.URL.createObjectURL(data), '_blank')
        })
      },