Ho to use axios inside a plugin
-
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”);
}, -
Found …
import Vue from ‘vue’;
import axios from ‘axios’;…
Vue.prototype.$axios.post( …
instead of
this.$axios.post( … -
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 -
-
This post is deleted!