Answer the question
In order to leave comments, you need to log in
How to call a method in router-link?
Hello. How can a method be called inside a router-link? That is, something like this:
router-link(tag="div", :to="{path: '/user/'+ getUserId(result.id)}")
getUserId(uid) {
axios.get("http://127.0.0.1:3000/blabla/"+uid).then((response) => {
return response.data[0].id;
});
}
Answer the question
In order to leave comments, you need to log in
axios.get returns nothing, so undefined.
As an option:
data() {
return {
userId: 0
}
},
mounted () {
this.getUserId(id)
},
methods: {
getUserId(uid) {
axios.get("http://127.0.0.1:3000/blabla/"+uid).then((response) => {
this.userId = response.data[0].id;
}).catch(error => {
console.log(error);
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question