Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Make library available across entire svelte app

$
0
0

I'm Building my first app with svelte. Since I'm using axios to fetch data from my laravel api endpoint, I need to import axios across different components with some default settings, especially I need to import axios in some store files. What I did is to import inside my entry point app.svelte axios like this

<!-- App.svelte --><script>      // Axios      import axios from 'axios';      window.axios = axios;    // Axios defaults axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';      axios.defaults.withCredentials = true;      axios.defaults.withXSRFToken = true;    //....</Script>

At this point I can use axios in all components and layouts across my app without importing again, but unfortunately if I call axios inside any store file, I will receive "error axios is undefined "and I have to import axios and defaults again in each store file. I tried to put the import and defaults inside main.js but is not working even from there, looks like store files are initialized before anything else or probably this is not the correct way to import common libraries. Any suggestion for this?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>