Skip to content

LoadingButton Component

A reusable button component with built-in loading state indicator (spinner).
Perfect for form submissions, API requests, or any async action where you want to block multiple clicks.


Usage

vue
<template>
  <div>
    <LoadingButton classes="btn btn-primary" :isLoading="loading" type="submit">
      Submit
    </LoadingButton>

    <button @click="toggleLoading">Toggle Loading</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
    }
  },
  methods: {
    toggleLoading() {
      this.loading = !this.loading
    },
  },
}
</script>

Props

PropTypeDefaultDescription
classesStringCustom CSS classes to style the button
isLoadingBooleanfalseIf true, shows a spinner and disables the button
disabledBooleanfalseDisables the button manually
typeString"button"Button type (button, submit, reset)
titleString

Features

  • Built-in loading spinner
  • Auto-disables button when loading
  • Accepts custom CSS classes
  • Works with type="submit" for forms
  • Prevents multiple clicks during async actions

Example: API Submit Button

vue
<template>
  <form @submit.prevent="submitForm">
    <LoadingButton classes="btn btn-success" :isLoading="loading" type="submit">
      Save Changes
    </LoadingButton>
  </form>
</template>

<script>
export default {
  data() {
    return { loading: false }
  },
  methods: {
    async submitForm() {
      this.loading = true
      await new Promise((resolve) => setTimeout(resolve, 2000)) // simulate API
      this.loading = false
      alert('Form submitted!')
    },
  },
}
</script>