Commit 6e586c5 1 parent 52db4b4 commit 6e586c5 Copy full SHA for 6e586c5
File tree 3 files changed +51
-1
lines changed
3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 2
2
node_modules
3
3
package.json
4
4
tsconfig.json
5
+ README.md
Original file line number Diff line number Diff line change 1
1
# nuxt-remote-functions
2
2
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
+ ```
4
52
5
53
## Development
6
54
Original file line number Diff line number Diff line change
1
+ import { H3Event } from 'h3'
1
2
import { prisma } from './prisma'
2
3
3
4
export async function getTodos ( ) {
You can’t perform that action at this time.
0 commit comments