/ Gists / Importing JSON file
On gists

Importing JSON file

JavaScript Vue.js

foo.js Raw #

// 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;
});