On the server
One file per action, validated before your code runs.
Write the action once on the server. Call it from any component with validated input and typed results, without writing a single generic.
npx nuxi module add nuxt-actionsimport { z } from 'zod'export default defineAction({ input: z.object({ title: z.string() }), handler: async ({ input }) => ({ id: Date.now(), title: input.title, }),})<script setup lang="ts">import { createTodo } from '#actions'const { execute, data } = useAction(createTodo)const data: Ref<{
id: number
title: string
} | null>await execute({ title: 'Buy milk' })</script>Every release runs the same end-to-end suite on Nitro v2, Nitro v3, and a Nuxt 5 preview. How the server runtime is chosen
One file per action, validated before your code runs.
Composables that know every action's input and output.
The parts you would otherwise build yourself.
The file name becomes the endpoint, and #actions hands the component a typed reference to it.
1. Create server/actions/create-todo.ts
import { z } from 'zod'
export default defineAction({
input: z.object({
title: z.string().min(1, 'Title is required'),
}),
handler: async ({ input }) => {
return { id: Date.now(), title: input.title }
},
})2. Call it from app/pages/todos.vue
<script setup lang="ts">
import { createTodo } from '#actions'
const { execute, data, error } = useAction(createTodo)
</script>
<template>
<button @click="execute({ title: 'Buy milk' })">
Add todo
</button>
<p v-if="data">Created {{ data.title }}</p>
<p v-if="error">{{ error.message }}</p>
</template>Install the module, add a file to server/actions, and call it from a page.
npx nuxi module add nuxt-actions