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

    Using plugin quasar/vue in Vuex

    Help
    5
    12
    2864
    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.
    • M
      Max last edited by

      just import it

      import axios from 'axios'
      
      export function register ({commit}, form) {
        return axios.post('api/auth/register', form)
          .then(response => {
            commit('login', {token: response.data.token, user: response.data.user})
          })
      }
      
      danielsalles 1 Reply Last reply Reply Quote 0
      • benoitranque
        benoitranque last edited by benoitranque

        You can access Vuex’s vue instance using this._vm. Since you added to the Vue prototype, you can access your axios instance using this._vm.$httpAPI

        danielsalles 1 Reply Last reply Reply Quote 1
        • danielsalles
          danielsalles @benoitranque last edited by

          @benoitranque It is returning undefined.

          export const getMe = ({ commit, state }, payload) => {
            console.log('VM', this._vm) // return undefined
            commit(basicInfoUser, 'espera')
          }
          

          Do I have to change anything else?

          1 Reply Last reply Reply Quote 0
          • danielsalles
            danielsalles @Max last edited by

            @max But the idea is to use the instance that I created earlier. And not a new instance, understand?

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

              Sorry I had to be more specific. this._vm is only available after store has been initiated. Try running it in an action called from vue

              danielsalles 1 Reply Last reply Reply Quote 0
              • danielsalles
                danielsalles @benoitranque last edited by

                @benoitranque Do you speak pass this in payload? I do not understand very well, hehehe.

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

                  No I do not. Try this here, dispatch that action from a vue component

                  danielsalles 1 Reply Last reply Reply Quote 0
                  • danielsalles
                    danielsalles @benoitranque last edited by

                    @benoitranque Sorry, but I do not understand. I’m doing this.

                    /*
                    export const someAction = (state) => {}
                     */
                    
                    export const getMe = ({ commit, state }, payload) => {
                      console.log('VM', this._vm.$httpAPI) // :/
                      commit(basicInfoUser, 'espera')
                    }
                    

                    console.log

                    alt text

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

                      But how does someone solve this problem?

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        sumpfgottheit @danielsalles last edited by

                        I was able to achieve it using classic function definitions:

                        store/keys/actions.js:

                        export async function refreshKeys({commit}) {
                            const keys = await this._vm.$axios.get('path/to/api')
                            commit('setKeys', keys.data)
                        }
                        

                        @danielsalles : Hope this helps

                        1 Reply Last reply Reply Quote 0
                        • rstoenescu
                          rstoenescu Admin last edited by

                          The App Plugins docs page has been updated to better explain it. Make sure you read it again. (Refresh browser if you feel it’s served from cache).

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