Skip to content

Commit 6e586c5

Browse files
committed
Add readme
1 parent 52db4b4 commit 6e586c5

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ dist
22
node_modules
33
package.json
44
tsconfig.json
5+
README.md

README.md

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
11
# nuxt-remote-functions
22

3-
Remote Functions. Instead of Event Handlers.
3+
Remote Functions. Instead of Event Handlers (API).
4+
5+
## Install
6+
7+
```bash
8+
pnpm add nuxt-remote-fn
9+
```
10+
11+
```
12+
export default defineNuxtConfig({
13+
modules: [
14+
'nuxt-remote-fn',
15+
],
16+
})
17+
```
18+
19+
## Usage
20+
21+
Create and export your remote functions in `*.server.ts` files:
22+
23+
```ts
24+
// todo.server.ts
25+
// Environment: Server
26+
27+
import { prisma } from './prisma'
28+
29+
export async function getTodos () {
30+
const todos = await prisma.todo.findMany()
31+
return todos
32+
}
33+
```
34+
35+
```vue
36+
<script setup lang="ts">
37+
import { getTodos } from '~~/lib/todo.server'
38+
39+
const todos = await getTodos()
40+
</script>
41+
42+
<template>
43+
<ul>
44+
<li v-for="todo in todos" :key="todo.id">
45+
<NuxtLink :to="`/todos/${todo.id}`">
46+
{{ todo.title }}
47+
</NuxtLink>
48+
</li>
49+
</ul>
50+
</template>
51+
```
452

553
## Development
654

playground/lib/todo.server.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { H3Event } from 'h3'
12
import { prisma } from './prisma'
23

34
export async function getTodos () {

0 commit comments

Comments
 (0)