Based on the knowledge sources provided, there isn't a specific Nuxt-provided utility function that directly simplifies this exact conditional expression pattern.
However, Nuxt does provide some related functionality that might be helpful in certain scenarios:
- When working with data from API responses, you could use the
payload system to ensure proper serialization/deserialization of complex objects:
definePayloadReducer('Person', (value) => {
})
definePayloadReviver('Person', (value) => {
})
- For UI components, Nuxt UI (if you're using it) provides components like
UInputMenu and USelectMenu that have built-in handling for displaying object properties through the option-attribute prop:
<UInputMenu
v-model="selected"
:options="people"
option-attribute="name"
/>
Your specific conditional expression is a standard JavaScript pattern for safely accessing nested properties with fallbacks. While Nuxt doesn't have a built-in utility specifically for this pattern, you could create your own utility function if you use this pattern frequently:
export function getNestedProperty(obj, property, fallback = "") {
return typeof obj[property] === 'object' ? obj[property]?.name ?? fallback : obj[property] ?? fallback
}
Then use it in your template:
{{ getNestedProperty(stone, 'person', "") }}
If you're looking for more advanced solutions for handling optional chaining and nullish coalescing in templates, you might want to consider using computed properties to simplify your template expressions.