Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
one icon file for whole application (Vuejs, Nuxt)

how can I create one icon file for my whole app? Currently I import into every *.vue file the icons and declare them afterwards like you can see in the following example.

<template>
  <div>
    <v-icon>
      {{mdiCheck}}
    </v-icon>
  </div>
</template>

<script>
import {
  mdiClose,
  mdiCheck
} from '@mdi/js'

export default {
    data: () => ({
        mdiClose: mdiClose,
        mdiCheck: mdiCheck
}),
</script>

I use Nuxt. I want to define the icons in one central file and use them in all my project without importing and declaring the icons in every single file. How can I do that?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I would recommend creating a separate component:

components/icon.vue

template>
  <div>
    <v-icon>
      {{icons[name]}}
    </v-icon>
  </div>
</template>

<script>
import {
  mdiClose,
  mdiCheck
} from '@mdi/js'

export default {
    data: () => ({
        icons: {
          mdiClose: mdiClose,
          mdiCheck: mdiCheck
        }
    }),
    props: {
      name: {
        type: String,
        required: true
      }
    }
}

Than make the component global by creating a plugin

plugins/global-components.js

import Vue from 'vue'
import Icon from '../components/icon.vue'

Vue.component('icon', Icon)

Finally register the plugin in nuxt.config.js


export default {
    ...
    plugins: [
        { src: '~/plugins/global-components.js' }
    ]
}

Now, you can use this component everywhere like this:

template>
  <div>
    <icon name="mdiCheck" />
  </div>
</template>

<script>

export default {
  data: () => ({})
}

</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda