welcome to nuxt glorious

useGloriousFetch

A composables for data fetching and is useFetch or $fetch of nuxt framework.

useGloriousFetch is more advanced fetch , this fetch handle loading , error, share data and...


useGloriousFetch() this composables get one object parm with below interface

            
interface gloriousFetchOptions {
  gKey?: String
  params?: Object
  server?: Boolean
  is$?: Boolean
  lazy?: Boolean
  headers?: Object
  body?: Object
  keepResponse?: Boolean
  bodyType?: 'formData' | 'formDataCustom' | 'normal'
  method?: 'POST' | 'GET' | 'PATCH' | 'PUT' | 'DELETE' | 'HEAD'
  credentials?: 'same-origin' | 'include'
  watch?: Array<Object>
}

        

Let me give you more information about each of the Fetch Request features.

gKey :

gKey is glorious key , all fetch has one gkey and if you don't set this option we split url and end index of array is your gKey

gKey use for forms, response, loading and handel error

if you read information for GloriousStore continue to read more about gKey

when request sended you can get loading of GloriousStore().loading[gKey]

for get error can get of GloriousStore().forms[gKey].errors

bodyType :

if set 'formData' your object convert to form data and send to back

if set 'formDataCustom' you should set for `body` option one formData

if set 'normal' your object sended to back and by default is `normal`

body :

when set this `method` option automatic set `POST` and body is form body or json you want send to server

keepResponse :

when route changed response of glorious store removed so if you want keep this response in GloriousStore set this option true by default is false

validationRequest :

when you want send form body or send data to server , you can set validation before data sended for example in below code first should data fill until send

for now support ['required']

username : glorious , password : nuxt

username
password
            
const gs = GloriousStore()
gs.formCreate('login')
const login = () => {
    useGloriousFetch('/api/login', {
        validationRequest: {
            username: ['required'],
            password: ['required'],
        },
        body: gs.forms.login.form,
    })
}

        

is$ :

if set this true , useGloriousFetch is on $fetch !


config

config for global setting , set on nuxt.config

            
glorious:{
  fetch?: {
    baseURL?: string
    credentials?: 'same-origin' | 'include'
  }
}