Skip to content

Instantly share code, notes, and snippets.

@fabianeichinger
Created September 2, 2021 15:23
Show Gist options
  • Save fabianeichinger/5d00313b133c8d8a5c2a6331cff9c73d to your computer and use it in GitHub Desktop.
Save fabianeichinger/5d00313b133c8d8a5c2a6331cff9c73d to your computer and use it in GitHub Desktop.
Vue 2 Custom Input Component Skeletons

Radio Button

<template>
  <label
    :class="isChecked ? 'bg-red' : 'bg-green'"
  >
    <input
      type="radio"
      v-bind="$attrs"
      :value="value"
      :checked="isChecked"
      @change="$emit('change', $event.target.value)"
    >
      {{ label }}
    </label>
  </label>
</template>
<script>
export default {
  inheritAttrs: false,
  model: {
    prop: 'checked',
    event: 'change'
  },
  props: {
    checked: {
      type: String,
      required: true
    },
    value: {
      type: String,
      required: true
    },
    label: {
      type: String,
      required: true
    }
  },
  computed: {
    isChecked () {
      return this.value === this.checked
    }
  }
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment