[Vuejs]-Make JSON visible from page without using imports in vuejs

0👍

If you serve your json file as static file. You can use fetch api or any other fetch library to access your json file.

fetch('path/to/your.json')
  .then(response => response.json())
  .then(data => {
    // do something
  })

See more about Fetch API.

In case you want to pass some json data as url query. Don’t forget to use encodeURIComponent or btoa to escape some special characters.

window.open('/some/path?data=' + encodeURIComponent(JSON.stringify(data)))

0👍

I have solved it by using Vuex and setting the JSON in the state of Vuex, so it can be accessible from other pages.

Leave a comment