Api

Nuxt App Hooks

Last updated by Harlan Wilton in chore: lint.

scripts:updated

  • Type: async (ctx: { scripts: ScriptRegistry }) => HookResult

Triggered after Nuxt updates the script status.

Nuxt uses this internally for the DevTools, but you can use it however you see fit.

plugins/nuxt-scripts.ts
export default defineNuxtPlugin({
  setup() {
    useNuxtApp().hooks.hook('scripts:updated', (ctx) => {
      console.log('Scripts updated', ctx.scripts)
    })
  }
})

script:instance-fn

  • Type: (ctx: { script: ScriptInstance<any>, fn: string | symbol, args: any, exists: boolean }) => HookResult

This is exposed only from Unhead, it's fired when accessing properties via the proxy instance.

Nuxt also uses this internally for the DevTools, but you can use it however you see fit.

export default defineNuxtPlugin({
  setup() {
    const head = injectHead()
    head.hooks.hook('script:instance-fn', ({ fn, args }) => {
      console.log('Function called:', ctx)
    })
    const { proxy } = useScript()
    proxy.doSomething() // Function called: doSomething
  }
})