1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <!-- MyButton.vue --> <template> <button :class="[ 'my-button', sizeClass, { round, square } ]" :style="buttonStyle" @click="$emit('click')" > {{ label }} </button> </template>
<script setup> import { computed } from 'vue'
defineProps({ color: { type: String, default: '#1976d2' }, textColor: { type: String, default: '#ffffff' }, label: { type: String, default: 'Click Me' }, size: { type: String, default: 'medium' }, // 'small' | 'medium' | 'large' round: { type: Boolean, default: false }, square: { type: Boolean, default: false } })
const props = defineProps()
const sizeClass = computed(() => { return { small: 'btn-sm', medium: 'btn-md', large: 'btn-lg' }[props.size] || 'btn-md' })
const buttonStyle = computed(() => ({ backgroundColor: props.color, color: props.textColor, })) </script>
<style scoped> .my-button { border: none; cursor: pointer; padding: 0.5em 1em; font-size: 1rem; transition: 0.2s; }
.btn-sm { padding: 0.3em 0.6em; font-size: 0.8rem; }
.btn-md { padding: 0.5em 1em; font-size: 1rem; }
.btn-lg { padding: 0.75em 1.5em; font-size: 1.2rem; }
.round { border-radius: 999px; }
.square { border-radius: 0; } </style>
|