mirror of
https://github.com/wanderer-industries/wanderer
synced 2025-12-12 02:35:42 +00:00
32 lines
873 B
TypeScript
32 lines
873 B
TypeScript
export default {
|
|
content: '',
|
|
|
|
mounted() {
|
|
const hook = this;
|
|
const button = this.el;
|
|
|
|
button.addEventListener('click', function () {
|
|
// Create a Blob from the JSON string
|
|
const blob = new Blob([hook.el.dataset.content || '{}'], { type: 'application/json' });
|
|
|
|
// Create a link element
|
|
const link = document.createElement('a');
|
|
|
|
// Set the download attribute with a filename
|
|
link.download = `${hook.el.dataset.name}.json`;
|
|
|
|
// Create a URL for the Blob and set it as the href attribute
|
|
link.href = URL.createObjectURL(blob);
|
|
|
|
// Append the link to the body (it won't be visible)
|
|
document.body.appendChild(link);
|
|
|
|
// Programmatically click the link to trigger the download
|
|
link.click();
|
|
|
|
// Remove the link from the document
|
|
document.body.removeChild(link);
|
|
});
|
|
},
|
|
};
|