How to use function with return value #9666
Unanswered
krasig
asked this question in
Help/Questions
Replies: 3 comments 2 replies
-
The problem is that you don't return anything from your function, so it has no return value. You need to return the promise that axios.get returns: function goLoadData(parm){
return axios
.get('.......?myParam='+parm)
.then((response) => {
retund respone.data
}
...
..
} then you can await that promise in the onMounted(()=>{
data.value = await goLoadData(XXX)
....
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
see my last code: const loadEkatte = async (codeParent) =>{
await axios
.get('............./getEkatte?codeParent='+codeParent)
.then((response) => {
return response.data;;
})
.catch((error) => {
console.log("Error:" + error)
console.log("Error.JSON" + error.toJSON)
wsError.value = error
})
}
onMounted(async ()=>{
oblasti.value = await loadEkatte(0,oblasti) And this isn't working. The only way i fond is next: const loadEkatte = async (codeParent,**myVar**) =>{
console.log("go loadEkatte start")
await axios
.get('............./getEkatte?codeParent='+codeParent)
.then((response) => {
console.log(response)
**myVar.value=response.data**
// console.log(oblasti.value)
return names;
})
.catch((error) => {
console.log("Error:" + error)
console.log("Error.JSON" + error.toJSON)
wsError.value = error
})
console.log('go loadEkatte end')
}
onMounted(async ()=>{
console.log("onMounted start")
// oblasti.value =
await loadEkatte(0,**oblasti**) But I don't like that function have a side effect and not sure is this the correct way |
Beta Was this translation helpful? Give feedback.
1 reply
-
row 6 i have |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm very new in vue and have some general misunderstood. So See my problem:
I'm trying something very simple:
One page with some simple data that is loaded by axios
So i have function with parameter returning my data and in onMounted ai have something like this:
so the problem is that goLoadData rethurns nothing.
If i put data.value inside body of goLoadData - everything is ok
goLoadData is something like this
Can someone help me?
Beta Was this translation helpful? Give feedback.
All reactions