nuxt / framework

Old repo of Nuxt 3 framework, now on nuxt/nuxt

Home Page:https://nuxt.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question (module): How does one access module options?

mohsin opened this issue · comments

Question related to Branch: module

So I've defined the module options like this in the config:

export default defineNuxtModule({
  meta: {
    name: 'my-module',
    configKey: 'mymodule'
  },
  defaults: {
    foo: 'bar'
  },
  hooks: {
    'components:dirs'(dirs) {
      dirs.push({
        path: fileURLToPath(new URL('./components', import.meta.url))
      })
    }
  }
})

And in my project, I'm using it like:

export default defineNuxtConfig({
    modules: [
      'my-module',
    ],
    mymodule: {
      foo: 'someothervalue'
    },
})

As you can see in the original module setup, I'm using components import for custom components. Now I want to use the config value of foo inside my component's <script setup lang="ts"> so I can take that variable and pass it to a the component template's element attribute. How do I go about doing this?