Skip to content

Commit

Permalink
docs: update example and add new option
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed May 16, 2023
1 parent 752972b commit ab1a156
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/core/useFetch/index.md
Expand Up @@ -126,6 +126,25 @@ const { data } = useFetch(url, {
return ctx
},
})
console.log(data.value) // { title: 'Hunter x Hunter' }
```

You can also disallow `onFetchError` to modifies the response data by passing `false` to `allowFetchErrorReturnData` option.
```ts
const { data } = useFetch(url, {
allowFetchErrorReturnData: false,
onFetchError(ctx) {
// ctx.data can be null when 5xx response
if (ctx.data === null)
ctx.data = { title: 'Hunter x Hunter' } // Modifies the response data no longer works

ctx.error = new Error('Custom Error') // Modifies the error

return ctx
},
})

console.log(data.value) // null
```

### Setting the request method and return type
Expand Down

0 comments on commit ab1a156

Please sign in to comment.