useStore()
The useStore()
composable allows for fetching and storing your Base Store configuration.
store
Main data object populated by the load()
method.
Type
const Stores: ComputedProperty<BaseStore>
References: BaseStore
loading
Indicates whether any of the composable methods is in progress.
Type
const loading: ComputedProperty<boolean>;
error
Contains errors thrown by any of the composable methods.
Type
const error: ComputedRef<UseStoreError>;
References: UseStoreError
load()
Fetches a Base Store configuration from the API and saves it to the store property. Under the hood, it sends a request to the getBaseStore API endpoint.
Good to know
This method is called by the loadStore plugin on the initial application load.
Type
interface LoadStoreProps extends BaseProps {
baseStoreUid?: string;
}
async function load(props?: LoadStoresProps): Promise<void>;
References: LoadStoresProps, BaseProps
Example
In the following example, we are calling the load()
method without any params. It will fetch configuration for the Base Store with uid
equal to the baseSiteId
provided in middleware.config.js.
import { useStore } from '@vsf-enterprise/sapcc';
import { onMounted } from '@nuxtjs/composition-api';
export default {
setup() {
const { store, load: loadStore } = useStore();
onMounted(async () => {
await loadStore();
});
return { store };
}
};
Example
In the following example, we are specifying which Base Store we want to fetch the configuration for. We are also specifying a subset of fields we want to receive in response.
import { useStore } from '@vsf-enterprise/sapcc';
import { onMounted } from '@nuxtjs/composition-api';
export default {
setup() {
const { store, load: loadStore } = useStore();
onMounted(async () => {
await loadStore({ baseStoreUid: 'apparel-uk', fields: 'BASIC' });
});
return { store };
}
};