Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active March 27, 2024 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/bbf2f9a8607eed6dc4c99e009e9a7ce6 to your computer and use it in GitHub Desktop.
Save Kcko/bbf2f9a8607eed6dc4c99e009e9a7ce6 to your computer and use it in GitHub Desktop.
// ES 6, JS without bundlers
// 1) fetch('data.json').then().then() ...
// 2) import data from './data.json' assert { type: 'json' };
// Vue
async function fetchData() {
try {
const response = await import('@/data.json');
const data = await response.default; // Získání dat z Promise
console.log(data);
} catch (error) {
console.error('Chyba při načítání dat:', error);
}
}
// Or
const o = ref([]);
const data = import('@/data.json').then(x => {
o.value = x.default;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment