Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. /**
  2. * downloadLocalJson(jsonObject, fileName)
  3. * 根据 jsonObject 下载 json 文件
  4. * @param jsonObject json对象
  5. * @param fileName 文件名称
  6. */
  7. export default (jsonObject, fileName) => {
  8. const URL = window.URL
  9. const blob = new window.Blob(
  10. [JSON.stringify(jsonObject, null, 2)],
  11. { type: 'application/octet-stream' }
  12. )
  13. const url = URL.createObjectURL(blob)
  14. const a = document.createElement('a')
  15.  
  16. a.href = url
  17. a.download = fileName
  18. a.click()
  19.  
  20. URL.revokeObjectURL(url)
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement