mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-01-21 07:21:43 +01:00
update router location
This commit is contained in:
@@ -21,10 +21,10 @@ export default defineNuxtConfig({
|
||||
|
||||
## Usage
|
||||
|
||||
Create your tRPC [routes](https://trpc.io/docs/router) and [context](https://trpc.io/docs/context) under `server/fn/index.ts`:
|
||||
Create your tRPC [routes](https://trpc.io/docs/router) and [context](https://trpc.io/docs/context) under `~/trpc/index.ts`:
|
||||
|
||||
```ts
|
||||
// ~/server/fn/index.ts
|
||||
// ~/trpc/index.ts
|
||||
import type { inferAsyncReturnType } from '@trpc/server'
|
||||
import * as trpc from '@trpc/server'
|
||||
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
const { data, pending } = useLazyTrpcQuery('getUser', {
|
||||
const client = useClient()
|
||||
const data = await client.query('getUser', {
|
||||
name: 'roberts',
|
||||
})
|
||||
|
||||
watchEffect(() => {
|
||||
console.log(data.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="pending">
|
||||
Loading...
|
||||
</div>
|
||||
<div v-else>
|
||||
<div>
|
||||
{{ data }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -38,7 +38,7 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
await fs.writeFile(clientPath, `
|
||||
import * as trpc from '@trpc/client'
|
||||
import { createTRPCComposables } from 'trpc-nuxt/client'
|
||||
import { router } from '~/server/fn'
|
||||
import type { router } from '~/trpc'
|
||||
|
||||
const client = trpc.createTRPCClient<typeof router>({
|
||||
url: process.browser ? '/trpc' : 'http://localhost:3000/trpc',
|
||||
@@ -61,7 +61,7 @@ export default defineNuxtModule<ModuleOptions>({
|
||||
|
||||
await fs.writeFile(handlerPath, `
|
||||
import { createTRPCHandler } from 'trpc-nuxt/api'
|
||||
import * as functions from '~/server/fn'
|
||||
import * as functions from '~/trpc'
|
||||
|
||||
export default createTRPCHandler({
|
||||
router: functions.router,
|
||||
|
||||
Reference in New Issue
Block a user