Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- struttura vue
- src/http-call/http-interceptor.js
- */
- /*----------------------- http-interceptor.js -----------------------*/
- import axios from "axios";
- import { API } from "../../public/config.json"; // questo è quello che usavo prima, però per cambiare il valore devo buildare di nuovo
- import Vue from "vue"; // il progetto e io devo poter cambiare questo e altri valori anche
- // se l'applicazione è già in produzione
- /*
- Qui è dove il Vue.prototype.$configJson è undefined
- */
- export const http = axios.create({
- baseURL: API,
- headers: {
- "Content-Type": "application/json",
- "Access-Control-Allow-Origin": "*",
- },
- });
- /*
- importo questa costante in tutti i file in cui ho bisogno di effettuare chiamate http.
- */
- /*----------------------- main.js -----------------------*/
- il file config è nella cartella public/
- axios
- .get(`${process.env.BASE_URL}config.json`)
- .then((resp) => {
- Vue.prototype.$configJson = resp.data;
- new Vue({
- store,
- router,
- render: (h) => h(App),
- }).$mount("#app");
- })
- .catch((err) => console.log(err));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement