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

    Ho to use axios inside a plugin

    Help
    4
    5
    935
    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.
    • E
      edudesouza last edited by

      Hi there,

      I’m updating my app from 0.13 to 0.17.

      In my old app I have in main.js a function to handle all ajax request.
      Now in the new version I have a plugin to handle this, although, I’am experiencing some issues with axios:

      Error in event handler for “click”: “TypeError: Cannot read property ‘post’ of undefined”

      My code:

      const funcoes = {

      enviar: function(url,dados_form){

      this.$axios.post(url,dados_form,{emulateJSON: true},{headers:{‘Cache-Control’: ‘no-cache’}}
      ).then(response =>{

        Loading.hide();
        var resultado = response.data.result;
      

      console.log(“OK”);

      },response => {
      Loading.hide();
      console.log(“ERRO”);
      },

      1 Reply Last reply Reply Quote 0
      • E
        edudesouza last edited by

        Found …

        import Vue from ‘vue’;
        import axios from ‘axios’;

        …

        Vue.prototype.$axios.post( …
        instead of
        this.$axios.post( …

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

          you can make an axios plugin so you have one instance of it throughout your app and use this.$axios in your .vue files. https://quasar-framework.org/guide/app-plugins.html#Examples-of-app-plugins

          1 Reply Last reply Reply Quote 0
          • s.molinari
            s.molinari last edited by

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

            Scott

            1 Reply Last reply Reply Quote 0
            • C
              chankl78 last edited by chankl78

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • First post
                Last post