mirror of
https://github.com/ArthurDanjou/trpc-nuxt.git
synced 2026-02-01 04:37:55 +01:00
update example
This commit is contained in:
@@ -1,19 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
const counter = useCookie('counter')
|
|
||||||
counter.value = counter.value || Math.round(Math.random() * 1000)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<h1> Counter: {{ counter || '-' }}</h1>
|
|
||||||
<button @click="counter = null">
|
|
||||||
reset
|
|
||||||
</button>
|
|
||||||
<button @click="counter--">
|
|
||||||
-
|
|
||||||
</button>
|
|
||||||
<button @click="counter++">
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -25,11 +25,8 @@ const addTodo = async () => {
|
|||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log($client)
|
|
||||||
const { data: todos, pending, error } = await $client.todo.getTodo.query(2, {
|
const { data: todos, pending, error, refresh } = await $client.getTodos.query()
|
||||||
// immediate: false,
|
|
||||||
pick: ['completed'],
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -40,26 +37,20 @@ const { data: todos, pending, error } = await $client.todo.getTodo.query(2, {
|
|||||||
<div v-else-if="error?.data?.code">
|
<div v-else-if="error?.data?.code">
|
||||||
Error: {{ error.data.code }}
|
Error: {{ error.data.code }}
|
||||||
</div>
|
</div>
|
||||||
<!-- <div v-if="todos && todos.length > 0">
|
<div v-else>
|
||||||
<ul>
|
<ul>
|
||||||
<li v-for="t in todos.slice(0, 10)" :key="t.id">
|
<li v-for="t in todos?.slice(0, 10)" :key="t.id">
|
||||||
<NuxtLink :class="{ completed: t.completed }" :to="`/todo/${t.id}`">
|
<NuxtLink :class="{ completed: t.completed }" :to="`/todo/${t.id}`">
|
||||||
Title: {{ t.title }}
|
Title: {{ t.title }}
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</li>
|
</li>
|
||||||
</ul> -->
|
</ul>
|
||||||
<button @click="addTodo">
|
<button @click="addTodo">
|
||||||
Add Todo
|
Add Todo
|
||||||
</button>
|
</button>
|
||||||
<!-- <button @click="() => refresh()">
|
<button @click="() => refresh()">
|
||||||
Refresh
|
Refresh
|
||||||
</button>
|
</button>
|
||||||
<button @click="addHeader">
|
|
||||||
Add header
|
|
||||||
</button> -->
|
|
||||||
<!-- </div> -->
|
|
||||||
<div v-if="todos">
|
|
||||||
{{ JSON.stringify(todos) }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(route.params.id)])
|
const { $client } = useNuxtApp()
|
||||||
|
const { data: todo, pending, error } = await $client.todo.getTodo.query(Number(route.params.id))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -11,8 +12,8 @@ const { data: todo, pending, error } = await useAsyncQuery(['getTodo', Number(ro
|
|||||||
{{ error.data.code }}
|
{{ error.data.code }}
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else>
|
||||||
ID: {{ todo.id }} <br>
|
ID: {{ todo?.id }} <br>
|
||||||
Title: {{ todo.title }} <br>
|
Title: {{ todo?.title }} <br>
|
||||||
Completed: {{ todo.completed }}
|
Completed: {{ todo?.completed }}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { httpBatchLink } from '@trpc/client'
|
import { httpBatchLink } from '@trpc/client'
|
||||||
import { createTRPCNuxtProxyClient } from 'trpc-nuxt/client'
|
import { createTRPCNuxtProxyClient } from 'trpc-nuxt/client'
|
||||||
|
import type { AppRouter } from '~~/server/trpc'
|
||||||
|
|
||||||
export default defineNuxtPlugin(() => {
|
export default defineNuxtPlugin(() => {
|
||||||
const client = createTRPCNuxtProxyClient({
|
const client = createTRPCNuxtProxyClient<AppRouter>({
|
||||||
links: [
|
links: [
|
||||||
httpBatchLink({
|
httpBatchLink({
|
||||||
url: 'http://localhost:3000/trpc',
|
url: 'http://localhost:3000/trpc',
|
||||||
|
|||||||
Reference in New Issue
Block a user