@2alheure/vue-toggle 中文文档教程

发布于 3年前 浏览 24 项目主页 更新于 3年前

Vue.js Toggle button

一个简单的 Vue.js 切换按钮。
此组件与 Vue 3 兼容。

它的灵感来自 ALEXANDRU STRATULAT 的这篇文章 ,所以如果您想了解它是如何工作的,请查看它。

Simple usage

首先运行 npm install @2alheure/vue-toggle
然后它的用法很简单:

<template><Toggle v-model="isToggled" /></template>

<script>
import Toggle from "@2alheure/vue-toggle";

export default {
  components: {
    Toggle
  },
  data() {
    return {
      isToggled: false
    }
  }
};
</script>

请注意 v-model 指令,因为它可用作输入(本质上是一个输入)。

Props

NameTypeDefault valueDescription
nameStringSome random stringThe name of the inner input.
colorOKString#0d9488The color of the toggle when it is toggled ON.
colorKOString#6b7280The color of the toggle when it is toggled OFF.
widthString3remThe width of the toggle.
heightString1.5remThe height of the toggle.
modelValueBooleanfalseThe prop lnked to the v-model directive. (mandatory)

Events

Events

NameValue typeValueDescription
update:modelValueBooleanThe toggle valueEmitted each time the toggle switches

Vue.js Toggle button

A simple Vue.js toggle button.
This component is compatible with Vue 3.

It has been inspired by this article by ALEXANDRU STRATULAT, so check it out if you wish to understand how it works.

Simple usage

First run npm install @2alheure/vue-toggle.
Then its usage is simple :

<template><Toggle v-model="isToggled" /></template>

<script>
import Toggle from "@2alheure/vue-toggle";

export default {
  components: {
    Toggle
  },
  data() {
    return {
      isToggled: false
    }
  }
};
</script>

Please note the v-model directive, as it is usable as an input (and is one, intrinsically).

Props

NameTypeDefault valueDescription
nameStringSome random stringThe name of the inner input.
colorOKString#0d9488The color of the toggle when it is toggled ON.
colorKOString#6b7280The color of the toggle when it is toggled OFF.
widthString3remThe width of the toggle.
heightString1.5remThe height of the toggle.
modelValueBooleanfalseThe prop lnked to the v-model directive. (mandatory)

Events

Events

NameValue typeValueDescription
update:modelValueBooleanThe toggle valueEmitted each time the toggle switches
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文