No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    axios object in store parameter from custom boot file

    Framework
    3
    4
    439
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      samodraland last edited by

      Hi guys,

      I made custom boot file and want to have axios in it. I found that $axios object comes from “store” parameter code bellow

      export default async ({ app, router, store, Vue }) => {
          console.log('store from custom boot file', store)
      }
      

      00263f22-798a-45e0-b7b8-d78d9ba78aa9-image.png

      just wondering:

      1. why does $axios (and $router as well) come from store and not from “app” or “Vue” (or “router”) parameter?
      2. what is the difference $axios & $router from store and “regular” this.$axios & this.$router from vue file?
      3. If I want to use $axios in my boot file just straight forward store.$axios.get("/path") or do I need to import?
      import axios from 'axios'
      

      btw Quasar Framework is really awesome! I loved it from the first time I knew it😻

      dobbel 1 Reply Last reply Reply Quote 0
      • dobbel
        dobbel @samodraland last edited by dobbel

        @samodraland

        1. It does not come from the store but is passed to the store so it’s just as easily available as in Vue components

        2. nothing it’s the same instance ( default)

        3. axios needs a boot file to setup. But if you want to use axios instance in another boot file you need to change a couple of things in the axios boot file.

        // axios.js boot file
        import axios from 'axios' 
        const axiosInstance = axios.create({ 
          baseURL: 'https://api.example.com' 
        })
        export default ({ Vue }) => {
          Vue.prototype.$axios = axiosInstance
        }
        export { axiosInstance }
        

        then you can import the axios instance in another boot file( or any .js file)

        // other boot file
        import axios from 'src/boot/axios.js'
        ect...
        

        See: https://medium.com/quasar-framework/adding-axios-to-quasar-dbe094863728

        1 Reply Last reply Reply Quote 0
        • metalsadman
          metalsadman last edited by metalsadman

          The prototype will be of same instance, so yeah, you can use this.$axios/this.$router in store just be sure you’re using function some action()... instead of arrows someaction= (..) => {...} when you defined your functions. I’m not sure why $axios was passed to store tho, other than for convenience.

          1 Reply Last reply Reply Quote 0
          • S
            samodraland last edited by

            Thank you for the explanations @dobbel and @metalsadman

            1 Reply Last reply Reply Quote 0
            • First post
              Last post