Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!