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

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

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 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!