swDefineOverride()
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 swDefineOverride<T extends Record<PropertyKey, unknown>>(bindings: T): void;Override files only. Declares which bindings of the component being overridden this file replaces.
A compile-time macro: you do not import it, the call itself is removed at build time, and it is mandatory in every .override.vue file.
What it does
Each name replaces the binding of that name in the component being overridden - a computed, a ref and a function alike. Read the original through useSwPreviousState() to build on it rather than discard it.
const previousState = useSwPreviousState();
const greeting = computed(() => `${previousState.greeting.value}!`);
swDefineOverride({ greeting });A name the component does not have is added as new state.
Each value must be a ref, a computed or a function. A reactive() object is merged into the original and must keep all of its keys. Any other value, such as a plain string or number, is ignored with a console error.
Pass {} for an override that only contributes markup through sw-block:
swDefineOverride({});Rules
Props cannot be overridden. A name that is one of the component's props is rejected with a console error - props come from whoever renders the component. Read them with useSwProps().
Shorthand bindings only. The key always equals the local binding name. Renaming, string keys, computed keys and spreads are rejected at build time.
Once, at the top level. A second top-level call is rejected. A call nested inside a function or block is not recognised as the marker, so the file is treated as having none.
Override files only. In a base component this macro is rejected; use swDefinePublic().
Order
Several overrides may target one component. They apply in registration order, and each sees the result of the ones before it, so they compose rather than compete.