vue.js 来回切换_vue.js的切换开关

vue.js 来回切换

vuejs切换开关 (vuejs-toggle-switch)

Toggle switch for vue.js.

切换vue.js。

vuejs-toggle-switch

Do you have questions or want a new feature? Use the "Issues" section :point_left:

您有疑问或想要新功能吗? 使用“问题”部分:point_left:

建立 (Setup)

install:

安装:

npm install vuejs-toggle-switch --save

Import: (in your main.js)

导入:(在您的main.js中)

import ToggleSwitch from 'vuejs-toggle-switch'
Vue.use(ToggleSwitch)

用法 (Usage)

Use: (in your local .vue file/component, html section)

使用:(在本地.vue文件/组件中的html部分)

<toggle-switch
  :options="myOptions"
  @change="updateMap($event.value)" // This is optional
  @selected="selectedMethod()" // This is optional
  v-model="selectedMapOption" // This is optional 2-way binding (try not to use both 1-way and 2-way)
  :value="selectedMapOption" // This is optional 1-way binding (try not to use both 1-way and 2-way)
  :group="switchGroup" // This is optional, use if multiple toggle-switch on same page with same label names
  /> 

<!-- Options struct: -->
myOptions: {
  layout: {
    color: 'black',
    backgroundColor: 'lightgray',
    selectedColor: 'white',
    selectedBackgroundColor: 'green',
    borderColor: 'black',
    fontFamily: 'Arial',
    fontWeight: 'normal',
    fontWeightSelected: 'bold',
    squareCorners: false,
    noBorder: false
  },
  size: {
    fontSize: 14,
    height: 34,
    padding: 7,
    width: 100
  },
  items: {
    delay: .4,
    preSelected: 'unknown',
    disabled: false,
    labels: [
      {name: 'Off', color: 'white', backgroundColor: 'red'}, 
      {name: 'On', color: 'white', backgroundColor: 'green'}
    ]
  }
}

物产 (Properties)

NameTypeDefaultDescription
widthNumber100Width of labels
heightNumber34Height
paddingNumber4Adjust text location in label with this
backgroundColorStringlightgrayBackground color (not selected)
colorStringblackText color (not selected)
borderColorStringgrayborder color
selectedColorStringwhiteText color selected label
selectedBackgroundColorStringgreenSelected label background color
fontFamilyStringArialFont of label text
fontWeightStringnormalFont weight item (not selected)
fontWeightSelectedStringboldFont weight selected item
fontSizeNumber14Text size
disabledBooleanfalseDisable switch
preSelectedStringOnSet (pre) selected label
labelsArrayOff/OnLabels for switch, name property is mandatory
valueStringn/aValue, ie: v-model="selectedMapOption"
delayNumber.4Transition delay between labels is seconds
squareCornersBooleanfalseRounded corners of switch
noBorderBooleanfalseRemove border
groupString''Switch key/group name (optional)
名称 类型 默认 描述
宽度 100 标签宽度
高度 34 高度
填充 4 使用此调整标签中的文本位置
背景颜色 浅灰 背景颜色(未选择)
颜色 黑色 文字颜色(未选中)
边框颜色 灰色 边框颜色
selectedColor 白色 文字颜色已选择标签
selectedBackgroundColor 绿色 所选标签的背景色
字体系列 Arial 标签文字的字体
fontWeight 正常 字体粗细项目(未选中)
fontWeightSelected 胆大 字体粗细选择项
字体大小 14 字体大小
残障人士 布尔型 禁用开关
预选 设置(预先)选择的标签
标签 数组 关/开 开关标签,名称属性是必需的
不适用 值,即:v-model =“ selectedMapOption”
延迟 .4 标签之间的转换延迟为秒
方角 布尔型 开关圆角
无边界 布尔型 移除边框
'' 切换键/组名(可选)

Labels prop can be used with or without color and backgroundColor attr, if not used the common prop:
selectedColor and selectedBackgroundColor will be used for all labels.

如果不使用常用道具,则标签道具可以有或没有color和backgroundColor attr使用:
selectedColor和selectedBackgroundColor将用于所有标签。

大事记 (Events)

NameDescription
changeTriggered on toggle, user selects switch option, returns current value. @change="vmValueItem = $event.value"
selectedTriggered whenever user select switch item
inputTriggered on mount if preSelected is set or value is set, and on toggle/change
名称 描述
更改 触发切换,用户选择开关选项,返回当前值。 @ change =“ vmValueItem = $ event.value”
已选 每当用户选择开关项目时触发
输入 如果设置了preSelected或设置了值,则在安装时触发,并且在切换/更改时触发

翻译自: https://vuejsexamples.com/toggle-switch-for-vue-js/

vue.js 来回切换

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值