Basic integration ok
This commit is contained in:
parent
2b6e3ad7fe
commit
ad65d9b2c3
|
@ -1,4 +1,4 @@
|
||||||
export function hello(name: string) {
|
export function hello(name: string) {
|
||||||
console.log(`hello ${name}`)
|
console.log(`Hello ${name}!`)
|
||||||
return { message: `hello ${name}` }
|
return { message: `Hello ${name}!` }
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ export const t = initTRPC.context<Context>().create()
|
||||||
|
|
||||||
export const appRouter = t.router({
|
export const appRouter = t.router({
|
||||||
hello: t.procedure.input(z.string()).query(({ input }) => {
|
hello: t.procedure.input(z.string()).query(({ input }) => {
|
||||||
|
if (input === 'test') throw new Error('Test error')
|
||||||
return hello(input)
|
return hello(input)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,22 +1,29 @@
|
||||||
<template>
|
<template>
|
||||||
<v-app>
|
<v-app>
|
||||||
<v-main> {{ message }}</v-main>
|
<v-main>
|
||||||
|
{{ message }}
|
||||||
|
<v-btn @click="fetchHello('Doug')">Doug</v-btn>
|
||||||
|
<v-btn @click="fetchHello('test')">test</v-btn>
|
||||||
|
</v-main>
|
||||||
</v-app>
|
</v-app>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { trpc } from './trpc'
|
import { trpc } from './trpc'
|
||||||
|
|
||||||
|
import { TRPCClientError } from '@trpc/client'
|
||||||
|
|
||||||
const message = ref('Hello World!')
|
const message = ref('Hello World!')
|
||||||
|
|
||||||
onMounted(async () => {
|
async function fetchHello(name: string) {
|
||||||
console.log('Hello')
|
|
||||||
try {
|
try {
|
||||||
const res = await trpc.hello.query('Doug')
|
message.value = (await trpc.hello.query(name)).message
|
||||||
message.value = res.message
|
} catch (error: any) {
|
||||||
} catch (err: any) {
|
if (error instanceof TRPCClientError) {
|
||||||
console.log(err)
|
console.dir(error)
|
||||||
|
message.value = error.message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user