Nuxt3 Plugins

import는 자동으로 된다.

  • plugins/testPlugins.ts
export default defineNuxtPlugin((nuxtApp) => {
    // Doing something with nuxtApp
    // console.log(nuxtApp);
    return {
        provide: {
            hello: (msg: string) => `Hello ${msg}!`,
        },
    };
});
  • pages/index.vue
<script setup>
    // alternatively, you can also use it here
    const { $hello } = useNuxtApp();
</script>

<template>
    {{ $hello('Good Morning') }}
</template>

Leave a Comment