Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

Génère le un snippet pour un button sur vue3

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-r1-0528’s answer.
  1. User

    Génère le un snippet pour un button sur vue3

  2. Claude Assistant

    Voici un snippet pour un composant bouton Vue 3 avec la Composition API :

    <template>
      <button 
        :class="buttonClasses"
        :disabled="disabled"
        @click="handleClick"
      >
        <slot>{{ text }}</slot>
      </button>
    </template>
    
    <script setup>
    import { computed } from 'vue'
    
    // Props
    const props = defineProps({
      text: {
        type: String,
        default: 'Button'
      },
      variant: {
        type: String,
        default: 'primary',
        validator: (value) => ['primary', 'secondary', 'danger'].includes(value)
      },
      size: {
        type: String,
        default: 'medium',
        validator: (value) => ['small', 'medium', 'large'].includes(value)
      },
      disabled: {
        type: Boolean,
        default: false
      }
    })
    
    // Emits
    const emit = defineEmits(['click'])
    
    // Computed
    const buttonClasses = computed(() => [
      'btn',
      `btn--${props.variant}`,
      `btn--${props.size}`,
      { 'btn--disabled': props.disabled }
    ])
    
    // Methods
    const handleClick = (event) => {
      if (!props.disabled) {
        emit('click', event)
      }
    }
    </script>
    
    <style scoped>
    .btn {
      border: none;
      border-radius: 4px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
      font-family: inherit;
    }
    
    .btn:focus {
      outline: 2px solid #007bff;
      outline-offset: 2px;
    }
    
    /* Variants */
    .btn--primary {
      background-color: #007bff;
      color: white;
    }
    
    .btn--primary:hover:not(.btn--disabled) {
      background-color: #0056b3;
    }
    
    .btn--secondary {
      background-color: #6c757d;
      color: white;
    }
    
    .btn--secondary:hover:not(.btn--disabled) {
      background-color: #545b62;
    }
    
    .btn--danger {
      background-color: #dc3545;
      color: white;
    }
    
    .btn--danger:hover:not(.btn--disabled) {
      background-color: #c82333;
    }
    
    /* Sizes */
    .btn--small {
      padding: 4px 8px;
      font-size: 12px;
    }
    
    .btn--medium {
      padding: 8px 16px;
      font-size: 14px;
    }
    
    .btn--large {
      padding: 12px 24px;
      font-size: 16px;
    }
    
    /* Disabled state */
    .btn--disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }
    </style>
    

    Utilisation du composant :

    <template>
      <div>
        <!-- Bouton simple -->
        <MyButton @click="handleClick">Cliquez-moi</MyButton>
        
        <!-- Bouton avec props -->
        <MyButton 
          variant="danger" 
          size="large" 
          @click="handleDelete"
        >
          Supprimer
        </MyButton>
        
        <!-- Bouton désactivé -->
        <MyButton :disabled="isLoading">
          {{ isLoading ? 'Chargement...' : 'Valider' }}
        </MyButton>
      </div>
    </template>
    
    <script setup>
    import MyButton from './components/MyButton.vue'
    
    const handleClick = () => {
      console.log('Bouton cliqué!')
    }
    
    const handleDelete = () => {
      console.log('Suppression...')
    }
    </script>
    

    Ce snippet inclut des props pour personnaliser l'apparence, des émissions d'événements, du styling responsive et une bonne accessibilité.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.