Skip to content

官方文档: https://nuxt.com/docs/4.x/getting-started/installation

bash
nvm 22
# 创建新的项目
pnpm create nuxt istr-nuxt-test
# 在Visual Studio Code中打开
code <project-name>
# 打开测试页面
pnpm dev -o

serve

js
Route Parameters


export default defineEventHandler((event) => {
  //server/api/hello/[name].ts,获取name值
  const name = getRouterParam(event, 'name')
  const id = parseInt(event.context.params.id) as number
  
  //server/api/foo/[...].ts 
	event.context.path // to get the route path: '/api/foo/bar/baz'
  event.context.params._ //to get the route segment: 'bar/baz'
  
  //server/api/foo/[...slug].ts
  event.context.params.slug //to get the route segment: 'bar/baz'
  
  //-----body
  const body = await readBody(event)
  
  //-----query
  const query = getQuery(event)
  
  return `Hello, ${name}!`
  
  //返回异常
  if (!Number.isInteger(id)) {
    throw createError({
      statusCode: 400,
      statusMessage: 'ID should be an integer',
    })
  }
  
  //状态码
  setResponseStatus(event, 202)
  
  //cookie
  const cookies = parseCookies(event)
  
  //302 redirect
  await sendRedirect(event, '/path/redirect/to', 302)
})

JWT timestamp claim value failed validation

discovered metadata issuer does not match the expected issuer