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

168
Vistas
Extending Vuetify's VBtn component to create a reusable icon button component

I've been using the example Codepen (https://codepen.io/whoistobias/pen/yLNgjwy) to try to extend the Vuetify VBtn component to create a reusable Button Icon component.

I'm awfully close, but as usual I'm stumbling at the last hurdle.

The main code is this:

const VBtn = Vue.options.components["VBtn"];
const VIcon = Vue.options.components["VIcon"];

const ButtonIcon = {
  name: 'ButtonIcon',
  
  extends: VBtn,

  props: {
    icon: {
      default: true,
      type: Boolean
    },
    iconColor: {
      default: 'info',
      type: String
    },
    iconName: {
      default: 'help',
      type: String
    },
    outline: {
      default: true,
      type: Boolean
    }
  },

  methods: {
    genContent () {
      return this.$createElement('div', {
        class: 'v-btn__content'
      }, this.$slots.default || [this.$createElement(
        VIcon,
        {
          props: {
            color: this.iconColor
          }
        },
        this.iconName
      )])
    }
  }
};

The bit that's not quite right is where the this.iconName is being inserted into the VIcon. The output of this is "add" instead of add when the prop iconName's value is add.

I've done my best to try digest the contents of the help docs around using createElement in the Vue docs - https://v2.vuejs.org/v2/guide/render-function.html?redirect=true#createElement-Arguments

Here's my forked Codepen of the working code: https://codepen.io/scp-nm/pen/PoQPVEP

Any help with this will be greatly appreciated.

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

0

The problem is your icon names are incorrect. The default icon names are prefixed with mdi-. You can see the list of available icons from https://materialdesignicons.com/.

I'm assuming mdi-plus is a good icon for "add", and mdi-help-circle-outline for "help":

                                               👇
<ButtonIcon icon-color="success" icon-name="mdi-plus" title="Icon Button (custom prop values)" />
const ButtonIcon = {
  ⋮
  props: {
    iconName: {   👇
      default: 'mdi-help-circle-outline',
      type: String
    },
  },
}

demo

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