Created
October 9, 2019 17:44
-
-
Save xargr/97f160e5ab1bbc513bc7a1acd4ed88e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default jsonData => { | |
const dataStr = JSON.stringify(jsonData); | |
const dataUri = `data:application/json;charset=utf-8, ${encodeURIComponent( | |
dataStr | |
)}`; | |
const exportFileDefaultName = 'data.json'; | |
// eslint-disable-next-line no-undef | |
const linkElement = document.createElement('a'); | |
linkElement.setAttribute('href', dataUri); | |
linkElement.setAttribute('download', exportFileDefaultName); | |
linkElement.click(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment