I changed the state value in action function, but it is reverted after returning the function.
These are the reproducible steps:
-
I used all the latest version as of 2021-01-31.
-
create a new directory then “framework7-cli create”
-
select minimal vue options.
-
Edit app.vue:
onMounted(() => { f7ready(() => { console.log('1.Simple=', f7.store.state.products); f7.store.dispatch('Simple').then((ret) => { console.log('3.Simple=', ret, f7.store.state.products); }); // Call F7 APIs here });
});
-
Edit store.vue
actions: { Simple({ state }) { state.products = [{ id: '99', title: 'XX', description: 'YY', }]; console.log('2.Simple=', state.products); return '123'; }, addProduct({ state }, product) {
-
This is the console output of mine:
1.Simple= (3) [{…}, {…}, {…}] 2.Simple= [{…}] 3.Simple= 123 (3) [{…}, {…}, {…}]
That shows
- original state has 3 products,
- I set one product in action, and console.log shows products has one.
- after returning from action, in app.vue, state.products is not changed.
Am I using the API incorrectly?
Thanks,