Skip to content

Commit 83b56c5

Browse files
author
PatrickSachs
committed
Fixed download network error
1 parent 99265cb commit 83b56c5

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"license": "",
2424
"dependencies": {
2525
"clean-webpack-plugin": "^2.0.0",
26+
"file-saver": "^2.0.1",
2627
"phaser": "^3.16.2",
2728
"phaser3-nineslice": "git+https://github.com/PatrickSachs/phaser3-nineslice.git#types",
2829
"vue": "^2.6.6",
@@ -31,6 +32,8 @@
3132
"vuetify": "^1.5.1"
3233
},
3334
"devDependencies": {
35+
"@types/file-saver": "^2.0.0",
36+
"@types/workbox-sw": "^3.2.0",
3437
"browser-sync": "^2.26.3",
3538
"browser-sync-webpack-plugin": "^2.2.2",
3639
"copy-webpack-plugin": "^5.0.1",
@@ -43,7 +46,6 @@
4346
"vue-template-compiler": "^2.6.6",
4447
"webpack": "^4.29.4",
4548
"webpack-cli": "^3.2.1",
46-
"@types/workbox-sw": "^3.2.0",
4749
"workbox-webpack-plugin": "^4.1.0"
4850
}
4951
}

src/components/App.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ import BackgroundSkin from "@/BackgroundSkin";
204204
import TreeType from "@/TreeType";
205205
import uuid from "@/utils/uuid";
206206
import LeavesGameObject from "@/gameobjects/LeavesGameObject";
207+
import FileSaver from "file-saver";
207208
208209
interface IMenuItem {
209210
id: string;
@@ -409,14 +410,10 @@ export default class STApp extends Vue {
409410
}
410411
411412
download(name: string, type: string, content: string) {
412-
const data = content.startsWith("data:")
413-
? content
414-
: "data:" + type + ";charset=utf-8," + encodeURIComponent(content);
415-
const a = document.body.appendChild(document.createElement("a"));
416-
a.download = name;
417-
a.href = data;
418-
a.click();
419-
document.body.removeChild(a);
413+
if (!content.startsWith("data:")) {
414+
content = "data:" + type + ";base64," + btoa(content);
415+
}
416+
FileSaver.saveAs(content, name);
420417
}
421418
422419
/**

0 commit comments

Comments
 (0)