Vue项目:js模拟点击a标签下载文件并重命名,URL文件地址下载方法、请求接口下载文件方法总结。

71 阅读2分钟

<a-button type="primary" icon="download" @click="downFile">下载

//文件下载

downFile() {

let fileUrl = imgView + 'group1/M00/00/88/FGQfoGIPDfuAErRaAABGAH4FyJ4422.xls' //服务器文件地址

this.getBlob(fileUrl).then(blob => {

this.saveAs(blob, '信用权证使用导入模板件名.xlsx')

})

},

在这里插入图片描述

以上是直接拿文件url地址下载。

请求接口下载文件方法: 以下方法仅供参考,项目不同,调用方法不同

vue组件

import { exportxlsx } from '@/api/api'

//导出

exportData() {

let req = {

createStartDate: this.startDate,

createEndDate: this.endDate,

status: this.status,

}

exportxlsx('/sys/mjBaseCount/exportMjGuaCountData', req).then(res => {

console.log(res);

this.loading = false

const content = res

const blob = new Blob([content])

const fileName = '担保方式统计.xlsx'

if ('download' in document.createElement('a')) {

// 非IE下载

const elink = document.createElement('a')

elink.download = fileName

elink.style.display = 'none'

elink.href = URL.createObjectURL(blob)

document.body.appendChild(elink)

elink.click()

URL.revokeObjectURL(elink.href) // 释放URL 对象

document.body.removeChild(elink)

} else {

// IE10+下载

navigator.msSaveBlob(blob, fileName)

}

})

}

api.js文件

import { exportFunc } from '@/api/manage'

//导出

const exportxlsx = (url, params) => {

params.brNo = "000000"

let req = {

"bizContent": JSON.stringify(params),

"msgTime": "2019-10-24 16:58:54",

"msgDate": "2019-9-4",

"timeStamp": 1571907534171,

"nonceStr": "WZuQFVCnNUueCGg94m5tvqB97kcaS4H2",

"version": "1",

"userId": params.userId ? params.userId : sessionStorage.getItem('USER_ID'),

"userName": sessionStorage.getItem('USER_NAME'),

"transCode": "",

"signType": "",

"brNo": sessionStorage.getItem('BR_NO'),

"appId": "client03",

"sourceId": "sys",

"sign": "8F38F92EFEB7306F4AE472E3CE637C54"

}

if (params.curBrNo !== '' &&

params.curBrNo !== null && typeof params.curBrNo !== "undefined") {

req.curBrNo = params.curBrNo

}

if (params.pageIndex !== '' &&

params.pageIndex !== null && typeof params.pageIndex !== "undefined") {

req.pageIndex = params.pageIndex

}

if (params.pageSize !== '' &&

params.pageSize !== null && typeof params.pageSize !== "undefined") {

req.pageSize = params.pageSize

}

let fullURL = url;

if (fullURL.indexOf('http') < 0 && fullURL.indexOf('https') < 0) {

fullURL = window._CONFIG['domianURL'] + fullURL;

}

return exportFunc(

fullURL,

req,

'post'

)

}

export{exportxlsx }

manage.js文件

import { axios } from '@/utils/request' //导入axios请求方法 request封装axios文件

export function exportFunc(url,parameter) {

return axios({

url: url,

method:'post' ,

data: parameter,

responseType: 'blob'

})

} 在这里插入图片描述

计算机网络

  • HTTP 缓存

  • 你知道 302 状态码是什么嘛?你平时浏览网页的过程中遇到过哪些 302 的场景?

  • HTTP 常用的请求方式,区别和用途?

  • HTTPS 是什么?具体流程

  • 三次握手和四次挥手

  • 你对 TCP 滑动窗口有了解嘛?

  • WebSocket与Ajax的区别

  • 了解 WebSocket 嘛?

  • HTTP 如何实现长连接?在什么时候会超时?

  • TCP 如何保证有效传输及拥塞控制原理。

  • TCP 协议怎么保证可靠的,UDP 为什么不可靠?

算法

  • 链表

  • 字符串

  • 数组问题

  • 二叉树

  • 排序算法

  • 二分查找

  • 动态规划

  • BFS

  • DFS

  • 回溯算法

开源分享:docs.qq.com/doc/DSmRnRG…