Answer the question
In order to leave comments, you need to log in
How to call a custom function in Axios (in Vue) on success (see code)?
This is a simple example code, I'm trying to do it like this:
<button @click="get">Get API...
...
methods: {
lg() {
console.log("Log 1");
},
lgt() {
console.log("Log 2");
},
get() {
this.axios
.get("https://api.coindesk.com/v1/bpi/currentprice.json")
.then(function(response) {
console.log(response);
this.lg();
});
},
}
Uncaught (in promise) TypeError: Cannot read property 'lg' of undefined at eval
methods: {
lg() {
console.log("Log 1");
this.lgt();
},
lgt() {
console.log("Log 2");
},
Answer the question
In order to leave comments, you need to log in
You need to use arrow functions
get() {
this.axios
.get("https://api.coindesk.com/v1/bpi/currentprice.json")
.then(response => {
console.log(response);
this.lg();
});
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question