当前位置: 首页 > article >正文

vue-----window.open打开新窗口文件并且修改窗口标题下载文件

vue-----window.open打开新窗口文件并且修改窗口标题&&下载文件

  // 下载word文件
  downloadFile(url, fileName) {
     const xhr = new XMLHttpRequest();
     xhr.open("GET", url, true);
     xhr.responseType = "blob";
     xhr.onload = function () {
       if (xhr.status === 200) {
         const blob = new Blob([xhr.response]);
         const a = document.createElement("a");
         const url = window.URL.createObjectURL(blob);
         a.href = url;
         a.download = fileName;
         a.click();
         window.URL.revokeObjectURL(url);
       }
     };
     xhr.send();
   },
openShowBtn(tag, url, fileName) {
      if (!url) return this.$message.error("文件为空!");
      if (tag === 2) { //打开新窗口
        const win = window.open("about:blank");
        win.document.title = fileName;
        const iframe = document.createElement("iframe");
        iframe.src = url;
        iframe.style.width = "100%";
        iframe.style.height = "100vh";
        iframe.style.margin = "0";
        iframe.style.padding = "0";
        iframe.style.overflow = "hidden";
        iframe.style.border = "none";
        win.document.body.style.margin = "0";
        win.document.body.appendChild(iframe);
      } else if (tag === 3) {//下载文件
        this.downloadFile(url, fileName);
      }
    },

http://www.kler.cn/news/289603.html

相关文章:

  • 云微客短视频矩阵系统,如何让企业赢在起跑线?
  • Flask框架默认session处理机制
  • gRPC学习之六:gRPC-Gateway集成swagger
  • 山东省行政执法证照片要求及图像处理方法
  • 实训day40(8.30)
  • 数据结构-广义表
  • 在uni-app中使用SQLite
  • office套件打开时 提示操作系统当前的配置不能运行此应用程序
  • VS2022使用指定的LLVM版本
  • windows 环境下安装OpenCV For Java
  • 一些可能很有用的矩阵知识
  • 新手c语言讲解及题目分享(十)——数组专项练习
  • 免费GPU平台教程,助力你的AI, pytorch tensorflow 支持cuda
  • Vue3组件通信概览
  • [Raspberry Pi]如何利用docker執行motioneye,並利用Line Notify取得即時通知和照片?
  • 2024车牌识别系统十大品牌发布,车牌智能识别系统品牌哪家好?
  • 【408 数据结构】第1章绪论
  • 开发基础软件安装地址(持续更新中)
  • Spring Boot实战:运用享元模式优化微服务间共享资源
  • 使用VM创建centos7环境
  • 知识点复习3
  • 速盾:什么是高防cdn?高防cdn的特点和好处有哪些?
  • 微信小程序知识点(一)
  • 自然语言处理系列五十三》文本聚类算法》文本聚类介绍及相关算法
  • 【软件文档】系统安全保证措施(Word)
  • 【代码随想录训练营第42期 Day49打卡 - 接雨水和柱状图最大矩形问题
  • HTML基本概述
  • 2024升级zblog小程序开源源码/基于uniapp开发的(支持微信小程序、百度小程序、安卓APP)
  • linux文件的拓展属性
  • pod基础和镜像拉取策略