Vuejs load static json file

I dont really like this solution but this is what Ive done:
index.html:

get the correct base href in there at compile time.

then in the client read it back out:

const baseHref = [document.getElementsByTagName['base'][0] || {}].href; export const appConfigPromise = axios.get['static/config.json', { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, baseURL: baseHref }] .then[[response: AxiosResponse] => { const { apiUrl } = response.data; return new Config[apiUrl]; }];

I would really love to know how to do this properly in Vue.js. In angular it seems to work more out of the box.

Video liên quan

Chủ Đề