mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-02-02 05:08:01 +01:00
update playground
This commit is contained in:
@@ -26,8 +26,6 @@ const addTodo = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { data: todos, pending, error, refresh } = await $client.todo.getTodos.query()
|
const { data: todos, pending, error, refresh } = await $client.todo.getTodos.query()
|
||||||
|
|
||||||
console.log(typeof $client.todo.getTodos.query)
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { httpBatchLink } from '@trpc/client'
|
import { httpBatchLink, loggerLink } from '@trpc/client'
|
||||||
import { createTRPCNuxtProxyClient } from 'trpc-nuxt/client'
|
import { createTRPCNuxtProxyClient } from 'trpc-nuxt/client'
|
||||||
import type { AppRouter } from '~~/server/trpc/routers'
|
import type { AppRouter } from '~~/server/trpc/routers'
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
const client = createTRPCNuxtProxyClient<AppRouter>({
|
const client = createTRPCNuxtProxyClient<AppRouter>({
|
||||||
links: [
|
links: [
|
||||||
|
// adds pretty logs to your console in development and logs errors in production
|
||||||
|
loggerLink({
|
||||||
|
enabled: opts =>
|
||||||
|
process.env.NODE_ENV === 'development'
|
||||||
|
|| (opts.direction === 'down' && opts.result instanceof Error),
|
||||||
|
}),
|
||||||
httpBatchLink({
|
httpBatchLink({
|
||||||
url: 'http://localhost:3000/api/trpc',
|
url: 'http://localhost:3000/api/trpc',
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export function createNuxtProxyDecoration<TRouter extends AnyRouter>(name: strin
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return useAsyncDataWithError(queryKey, () => (client as any)[path][lastArg](input), asyncDataOptions as Record<string, any>)
|
return useAsyncDataWithError(queryKey, () => (client as any)[path][lastArg](input), asyncDataOptions)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user