RE: RE: Nuxt开发指南
You are viewing a single comment's thread from:

RE: Nuxt开发指南

Words
20
Reading
1 min
Listen
Play
7M

transform 函数来对结果拦截,并做出一些处理逻辑。

const { data: mountains } = await useFetch('/api/mountains', {
  transform: (mountains) => {
    return mountains.map(mountain => ({ title: mountain.title, description: mountain.description }))
  }
})

// 只选择模板中使用的字段
const { data: mountain } = await useFetch('/api/mountains/everest', {
  pick: ['title', 'description']
})
<template>
  <h1>{{ mountain.title }}</h1>
  <p>{{ mountain.description }}</p>
</template>


const { data, pending, error, refresh } = await useFetch("/api/getonepost", config, {
  transform: (res) => {
    return res.result
  }
})
@lemooljiang: 用transform | Ecency