Skip to content

Instantly share code, notes, and snippets.

@summerscar
Last active February 19, 2019 08:00
Show Gist options
  • Save summerscar/0eaa5866a8b9f9096c8ccd3c20f472dc to your computer and use it in GitHub Desktop.
Save summerscar/0eaa5866a8b9f9096c8ccd3c20f472dc to your computer and use it in GitHub Desktop.
文件导入导出
function exportData(text) {
const saveLink = document.createElement('a')
document.body.appendChild(saveLink)
const data = new Blob([text], { type: 'text' })
const url = window.URL.createObjectURL(data)
saveLink.href = url
// File name: project-DATE-TIME
const date = new Date()
const timestamp = `${date.toLocaleDateString()}-${date.toLocaleTimeString()}`
saveLink.download = `block.${timestamp}.svg`
saveLink.click()
window.URL.revokeObjectURL(url)
document.body.removeChild(saveLink)
}
dom.change =function(e) {
const reader = new FileReader();
reader.onload = function() {
console.log(reader.result)
}
reader.readAsText(e.target.files[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment