Currently, I'm using Vuex for managing application-level state.
I need to store data only within the Vue component lifecycle. Is it possible to use Vuex for storing local component states without involving the global store?
For example, I have a component like that:
class SomeComponent extends Vue {
id = this.$props.componentId;
localData = {};
async created() {
this.localData = await apiClient.getDataById(this.id);
}
}
Then I can use components with different prop componentId
, and every component should manage its own state.
<SomeComponent componentId="1" />
<SomeComponent componentId="2" />
<SomeComponent componentId="3" />
So ideal variant I'd like to see:
import LocalStore from './local-store';
class SomeComponent extends Vue {
id = this.$props.componentId;
localStore = new LocalStore(); // <- this is the Vuex store
created() {
localStore.getDataById(this.id);
}
}