Composition-api: docs: How to access $loading inside setup() ?

Created on 2 May 2021  路  2Comments  路  Source: nuxt-community/composition-api

I just try to use the composition in Nuxt.

And i just wonder that, is that $loading.start() and finish() is available inside setup() ?

I searched in documentation and cannot found it, and i've tried using context property, but still can't find the helper function of $loading.

documentation

Most helpful comment

use wrapProperty

import { defineComponent, wrapProperty } from '@nuxtjs/composition-api'

export const useNuxt = wrapProperty('$nuxt', false)

export default defineComponent({
  const { $loading } = useNuxt()

  try {
    $loading.start()
    /* balabalabalabala */
  } catch (err) {
    console.error(err)
  } finally {
    $loading.finish()
  }
})

All 2 comments

use wrapProperty

import { defineComponent, wrapProperty } from '@nuxtjs/composition-api'

export const useNuxt = wrapProperty('$nuxt', false)

export default defineComponent({
  const { $loading } = useNuxt()

  try {
    $loading.start()
    /* balabalabalabala */
  } catch (err) {
    console.error(err)
  } finally {
    $loading.finish()
  }
})

thank you @mao-shonen, it worked like a charm.

Was this page helpful?
0 / 5 - 0 ratings