useSwPreviousState()
WARNING
Single File Component (SFC) support for Administration extensions is experimental. It is available since Shopware 6.7.16.0. The APIs described on this page can still change without a deprecation. Try it out and tell us what you find, but do not ship an extension built on it to customers or to the Shopware Store until the API is declared stable (planned for 6.9).
function useSwPreviousState<T extends Record<PropertyKey, any>>(): T;Provided by the build in every .override.vue file; you never import it. Returns the state of the component being overridden.
What you get
Everything that component exposes: its data, computed, methods and props while it is still an Options API component, or the names it passed to swDefinePublic() once it has been migrated.
const previousState = useSwPreviousState();
previousState.product.value; // read a value
previousState.save(); // run the original implementation of a methodCalling a method is how an override builds on behaviour instead of discarding it - the equivalent of this.$super() in the Options API.
Reading values
Values are refs, methods are plain functions. Read a value with .value in your script; a template unwraps it as it does any ref.
const name = previousState.product.value?.name;With several overrides
Each override sees the state as the ones registered before it left it, so a chain of overrides composes:
// second override in the chain
const greeting = computed(() => `${previousState.greeting.value} and again`);