赞
踩
a
标签,只能同源下载<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <div> <!-- a 标签下载 --> <a href="/04-a标签下载功能/test.png" download="demo">下载</a> <!-- 其他标签实现下载 同域 --> <div onclick="download()">下载</div> <!-- 其他标签实现下载 跨域 --> <div onclick="download1()">下载</div> </div> <script> // 同域 function download( url = '/04-a标签下载功能/test.png', title = 'demo2', artist = 'down' ) { const eleLink = document.createElement('a') // 新建A标签 eleLink.href = url || '/04-a标签下载功能/test.png' // 下载的路径 eleLink.download = `${title} - ${artist}` // 设置下载的属性,可以为空 eleLink.style.display = 'none' document.body.appendChild(eleLink) eleLink.click() // 触发点击事件 document.body.removeChild(eleLink) } // 跨域 function download1( url = 'https://upload-images.jianshu.io/upload_images/5809200-a99419bb94924e6d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240', title = 'demo3', artist = 'down' ) { var x = new XMLHttpRequest() x.open('GET', url, true) x.responseType = 'blob' x.onload = function () { const url = window.URL.createObjectURL(x.response) const eleLink = document.createElement('a') eleLink.href = url eleLink.download = `${title} - ${artist}` eleLink.style.display = 'none' document.body.appendChild(eleLink) eleLink.click() document.body.removeChild(eleLink) } x.send() } </script> </body> </html>
iframe
下载,支持跨域get请求export function iframeDownload(url, defaultMime = 'application/octet-stream') {
//创建iframe标签
const f = document.createElement('iframe');
//下载url
f.src = url;
// 设置不可见
f.style.display = 'none';
// 挂到body中
document.body.appendChild(f);
// 延时 注销iframe标签
setTimeout(function () {
document.body.removeChild(f);
}, 333);
}
Form
表单下载,支持跨域get和post请求export function downloadFileByForm( url: string, filename: string, method = 'get' ) { const form = document.createElement('form'); form.setAttribute('action', `${url}&bucketName=${config.bucketName}`); form.setAttribute('method', `${method}`); const input = document.createElement('input'); input.setAttribute('type', 'hidden'); input.setAttribute('name', 'filename'); input.setAttribute('value', `${filename}`); form.appendChild(input); document.body.appendChild(form); form.submit(); setTimeout(() => { document.body.removeChild(form); }, 100); }
FileSaver.js
StreamSaver.js
viewerjs
v-viewer
wangeditor
vxe-table
form-generator(简单)
form-create(全面)
vue-form-making
vee-validate
vuepress
blog-vue-typescript
blog-vue-springboot
docxtemplater
Luckysheet
X-Spreadsheet
excalidraw
D3
Echarts
Sortable
vue-draggable-resizable
qrcodejs2
vue-seamless-scroll
Canvas2image
tui.image-editor
spritejs
dom-to-image
signature_pad
watermark-dom
https://github.com/saucxs/watermark-dom
watermarkjs
https://github.com/brianium/watermarkjs
progressbar.js
https://github.com/kimmobrunfeldt/progressbar.js
DataV
http://datav.jiaminghi.com/
vue-video-player
一些API使用说明:https://blog.csdn.net/a772116804/article/details/123680790
案例说明:https://blog.csdn.net/m0_49714202/article/details/125312364
Print.js
https://github.com/crabbly/Print.js
vue-print-nb
PDFObject
https://github.com/pipwerks/PDFObject
vue-office
https://github.com/501351981/vue-office
mammoth.js
https://github.com/mwilliamson/mammoth.js
tailwindcss
https://www.tailwindcss.cn/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。