new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Nuxt · API · all subjects

utility functions & methods

3 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

$fetch.create for custom instance in plugins

You can create a custom $fetch instance using $fetch.create() in a Nuxt plugin. The create method accepts configuration with baseURL, onRequest, and onResponseError callbacks. The onRequest callback receives request, options, and error parameters. This custom instance can be provided via defineNuxtPlugin's provide property and used directly or passed to createUseFetch.

Custom $fetch instance plugin example

export default defineNuxtPlugin((nuxtApp) => { const { session } = useUserSession() const api = $fetch.create({ baseURL: 'https://api.nuxt.com', onRequest ({ request, options, error }) { if (session.value?.token) { options.headers.set('Authorization', `Bearer ${session.value?.token}`) } }, async onResponseError ({ response }) { if (response.status === 401) { await nuxtApp.runWithContext(() => navigateTo('/login')) } }, }) return { provide: { api, }, } }) This example shows creating a custom $fetch instance in a Nuxt plugin and providing it for use in components.

$fetch is a configured ofetch instance

$fetch is a configured instance of ofetch which supports adding the base URL of your Nuxt server as well as direct function calls during SSR, avoiding HTTP roundtrips.

Give your agent this brain