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

    Difficulty extracting axios.then response

    Framework
    2
    3
    76
    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.
    • O
      omgwalt last edited by omgwalt

      I can send an axios.post request without issues within Quasar, and I can get a response. However, other than running console.log or alert within .then(function(response)) I can’t seem to figure out how to get that information outside of .then’s function.

      For instance:

      methods: {
          ...mapActions('auth', ['loginUser']),
          anotherMethod(response) {
              alert('This works!')
          },
          submitForm() {
              axios
              .post('/authenticate.php', {
                  rememberme: true,
                  username: this.formData.userName,
                  password: this.formData.password
              })
              .then(function(response) {
                  console.log(response.data) // works just fine
                  alert(response.data) // works just fine
                  this.anotherMethod(response.data) // doesn't fire alert('This works!')
                  this.loginUser(response.data) // doesn't fire in Vuex store 'auth'
                  return response.data // I can't find any way to grab this
                  /* what can I do here to extract response.data from axios.then? */
              })
              .catch(function(error) {
                  console.log("Axios Error: ",error)
              })
          }
      }
      

      Any of the failed attempts simply produce “undefined” errors in console.log. Suggestions?

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

        @omgwalt use arrow function. Ie in your then callback response => { ... }.

        1 Reply Last reply Reply Quote 0
        • O
          omgwalt last edited by

          Thank you! That did the trick.

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