Scenario 1 - Using Vue3 + Pinia (optionsAPI) + Fetch (instead of AXIOS).
a. Within the same store, I am able to call another action (eg action_b) from an action (eg action_a) by using "this.action_b". (This is the response mentioned by FullStack Alex as above).
b. However, when I try to call action_b as part of a FETCH response in action_a, this does not work. In this situation the response provided by Назар Семенюк worked.
i.e., within action_a I had to call the store again as a variable (eg store_x) and then use it as a prefix to call action_b (store_x.action_b).
FETCH code used is as per the format provided in https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
export const useixStore = defineStore('ix', {
state: () => ({...}),
actions: {
action_b () {...},
action_a () {
...
const ix = useixStore(); // INTRODUCED TO MAKE THIS WORK
...
async function postData(url = "", data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
mode: "cors", // no-cors, *cors, same-origin
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
// "Content-Type": "application/json;charset=UTF-8",
},
redirect: "follow", // manual, *follow, error
referrerPolicy: "no-referrer", // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data), // body data type must match "Content-Type" header
});
return response.json(); // parses JSON response into native JavaScript objects
}
postData(url, i_json)
.then(function(res) {
...
this.action_b // THIS DOES NOT WORK
ix.action_b // THIS WORKED AFTER INTRODUCING ix WITHIN THIS action_a
...
});
....
Scenario 2 - Using Vue3 + Pinia (setup) + Fetch (instead of AXIOS).
In this scenario using Pinia (using setup instead of OptionsAPI), everything is normal.
a. Within the same store, I am able to call another action (eg action_b) from an action (eg action_a) by using "action_b". (This is similar to the response mentioned by FullStack Alex as above).
b. Even within a FETCH response, this works as expected and simple "action_b" works.