vuebeginnermitFeatured

Vue Toggle Switch

A styled toggle switch component.

6.9k1.9k564424

About this module

A Vue 3 toggle switch with <script setup>, v-model support, keyboard toggling and ARIA attributes.

#vue#toggle#switch#form

Source code

Installation

  1. 1

    Install Vue

    Create a Vue 3 project or add the component to an existing one.

    npm create vue@latest
  2. 2

    Create the component

    Create VueToggleSwitch.vue and paste the source below.

  3. 3

    Import and use

    Import the component in your page or parent component and render it.

Usage

  1. 1

    Import the component

    Import VueToggleSwitch in a parent component.

    import VueToggleSwitch from "./components/VueToggleSwitch.vue";
  2. 2

    Register and render

    Register it in your setup and render it in the template.

    <script setup>
    import VueToggleSwitch from "./components/VueToggleSwitch.vue";
    </script>
    
    <template>
      <vue-toggle-switch />
    </template>
Overview
Categorycomponents
Frameworkvue
Difficultybeginner
Licensemit
Versionv1.0.0
Features
  • Single-file component
  • TypeScript-friendly
  • Accessible by default
Traits
  • ResponsiveYes
  • Dark modeYes
  • AccessibleYes
  • Production readyYes
Props
modelValueboolean

The bound value (v-model target).

Default: false

labelstring

Accessible label for the switch.

Default: ""

disabledboolean

Disables interaction.

Default: false

Browser support
  • Chrome 90+
  • Firefox 90+
  • Safari 15+
  • Edge 90+

Related modules

Command Palette

Search modules and jump anywhere