Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda