szzxc 发表于 2022-7-28 15:13:20

油猴获取相关数据后,可以打印显示,但是好像没有办法...

例如用油猴获取相关数据后,可以打印显示,但是好像没有办法保存到本地文档。。

李恒道 发表于 2022-7-28 15:13:21

[油猴脚本开发指南]filesaver解决前端下载
https://bbs.tampermonkey.net.cn/thread-1147-1-1.html
使用filersaver库调用文件下载功能

steven026 发表于 2022-7-28 16:38:02

本帖最后由 steven026 于 2022-7-28 16:39 编辑

有3种方法
第一种:引用第三方库fileSaver,
详细见2L

第二种:利用油猴内置函数
需要声明权限// @grant GM_download
简单演示:GM_download(URL.createObjectURL(new Blob(["example text"])), "example.txt")

第三种:利用原生js
大致思路是在页面创建一个隐藏的<a>标签,href设为你要下载的内容链接
然后用click <a>标签,再删除<a>标签

(由于用的不是常用电脑,没同步收藏夹,无法给出具体教程)

Ne-21 发表于 2022-7-28 17:20:43

```js
this.$axios.get('/download',{
                params:{
                  "copyright": this.imgInfo.copyright,
                  "urlBase": this.imgInfo.urlbase,
                  "w":w,
                  "h":h
                },
                responseType: 'blob'
            }).then((data)=>{
                let blob = data.data
                let reader = new FileReader()
                reader.readAsDataURL(blob)
                reader.onload = (e) => {
                  let a = document.createElement('a')
                  a.download = this.imgInfo.copyright + "_" + w + "x" + h +".jpg"
                  a.href = e.target.result
                  document.body.appendChild(a)
                  a.click()
                  document.body.removeChild(a)
                }
                setTimeout(()=>{
                  this.dialogVisible = false
                  loading.close()
                },2000)
            })
```

可能对你有用,这实现的是下载图片

szzxc 发表于 2022-8-10 10:34:00

steven026 发表于 2022-7-28 16:38
有3种方法
第一种:引用第三方库fileSaver,
详细见2L


谢谢。。
页: [1]
查看完整版本: 油猴获取相关数据后,可以打印显示,但是好像没有办法...