vue3 两种下载方式

const downFile = (fileName:string)=>{

  // 设置响应类型为'blob'以接收二进制数据

  axios({

    method: 'get',

    url: urlIpi + '/common/download',

    params:{filename,delete:false}, // URL参数

   // responseType: 'blob', // 重要

  }).then(response => {

    download(fileName);

  }).catch(error => {

    console.error('下载失败:', error);

  });

}

const download=(fileName) => {

  let protocol = window.location.protocol

  let host = window.location.host

  let url = `${protocol}://${host}/${fileName}`;

  const a = document.createElement('a')

  a.setAttribute('download', fileName )

  a.setAttribute('target', '_blank')

  a.setAttribute('href', url)

  a.click()

}

第二种:

 <a id="downFile" href="http://xxxx.xxxx.xxx.xxxx:8081/common/download?fileName=%2F2024%2F05%2F21%2Fmetasec-license_20230521164939A003.docx" download="文件" class="app-margin-right-10">

      <i class="abc"></i>

    </a>

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue两种常见的路由方式,分别是Hash路由和History路由。 Hash路由是指在URL中加入#符号来表示路由路径的方式。它的实现原理是通过监听浏览器URL中的hash值的变化来切换页面内容,这种方式不会向后端发出请求,所有的路由都在前端进行解析和渲染。在Vue中,可以使用vue-router库来实现Hash路由。 History路由是指在URL中直接使用实际的路径来表示路由的方式,不再使用#符号。它的实现原理是通过利用HTML5中的History API来实现前端路由功能,可以实现无刷新切换页面内容。与Hash路由不同的是,History路由会向后端发出请求获取对应的页面内容。在Vue中,也可以使用vue-router库来实现History路由。 总结起来,Hash路由和History路由都是前端路由的实现方式,它们的主要区别在于URL的表示方式和是否向后端发出请求。对于选择使用哪种路由方式,可以根据具体的项目需求和开发情况来决定。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vue-router 源码实现前端路由的两种方式](https://download.csdn.net/download/weixin_38702726/12757939)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [VueRouter的两种模式](https://blog.csdn.net/weixin_43611411/article/details/127765556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值