Create a reusable button component in Vue with different variants (primary, secondary).

Code Playground
JavaScript (V8)
Loading...
Console Output
// Output will appear here...
// For React: ReactDOM.createRoot(rootElement).render(<App />);
Recommended Answer
<template>
  <button :class="variantClass">
    <slot></slot>
  </button>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  variant: {
    type: String,
    default: 'primary'
  }
});

const variantClass = computed(() => {
  return {
    'bg-blue-500 text-white': props.variant === 'primary',
    'bg-gray-500 text-white': props.variant === 'secondary'
  };
});
</script>