Level 51
is it the right mode to do it?
Yes. However, you can just write the following
actions: {
init(){
return axios.get("auth");
},
}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi all. I'd like to create a method in pinia that works like a promise so that when I call it I can do this:
myStore.init().then({
//my code
}).catch({
//my error code
});
How can I do it? In pinia store I try to do it:
export const UseAuthStore = defineStore('auth', {
actions: {
init(){
return new Promise((resolve,reject) => {
axios.get("auth",{}).then(resp => {
resolve(resp);
}).catch(err => {
reject(err);
});
})
},
})
is it the right mode to do it? thanks Hi all
is it the right mode to do it?
Yes. However, you can just write the following
actions: {
init(){
return axios.get("auth");
},
}
Please or to participate in this conversation.