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

    How to access axios inside store action?

    Help
    5
    6
    2659
    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.
    • R
      realtebo last edited by

      I have the standard boot file for axios

      import Vue from 'vue'
      import axios from 'axios'
      
      Vue.prototype.$axios = axios
      

      How can I access axios inside a vuex store action?

      1 Reply Last reply Reply Quote 0
      • T
        tof06 last edited by

        Just import axios in your action.js file

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

          @realtebo take the example from the docs https://quasar.dev/quasar-cli/cli-documentation/boot-files#Accessing-data-from-boot-files.

          BenceSzalai 1 Reply Last reply Reply Quote 1
          • R
            Robert last edited by Robert

            Here is a clip from my Vuex store.

            const actions = {
            async signIn({ dispatch, commit }, credentials) {
                console.log('login action' + JSON.stringify(credentials))
               var authenticateResponse = await this._vm.$axios.post("user/authenticate", credentials)
                // console.log("My user obj: " + JSON.stringify(authenticateResponse.data))
               // do something with response
              },
            ...
            }
            
            1 Reply Last reply Reply Quote 1
            • BenceSzalai
              BenceSzalai @metalsadman last edited by BenceSzalai

              @metalsadman said in How to access axios inside store action?:

              @realtebo take the example from the docs https://quasar.dev/quasar-cli/cli-documentation/boot-files#Accessing-data-from-boot-files.

              Also for anyone interested, the now broken link above has been moved here: https://quasar.dev/quasar-cli/boot-files#Accessing-data-from-boot-files

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

                You can simply assign your axios instance in a boot file.
                Inside src/boot/axios.js you can use this:

                import axios from 'axios'
                
                export default ({ store, Vue }) => {
                  Vue.prototype.$axios = axios
                  store.$axios = axios
                }
                

                Once it’s set up like this, axios can be accessed in your store actions as this.$axios.

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