Skip to content

Switch

基础用法

上架状态
Y
N

<template>
  <ai-form ref="formEl" :model="formInfo" :formConfig="formConfig"></ai-form>
</template>

<script setup>
import { reactive, computed } from 'vue'

const formInfo = reactive({
  status: 1,
})

const formConfig = computed(() => {
  return [
    {
      key: 'status',
      label: '上架状态',
      type: 'switch',
      model: 'status',
      prop: 'status',
      activeValue: 1,
      inactiveValue: 0,
      isBlock: true,
      required: true,
    },
  ]
})
</script>

Props

属性说明类型默认值
typeselectstring-
key配置列表唯一标识string-
label标签文本string-
model属性名,它可以是属性的路径(如a.b.0)也可以是一个方法,返回属性路径,该属性是必填的string/Function-
prop一般和属性名保持一致,在使用了validateresetFields的方法时,该属性是必填的string/Function-
width宽度(1-24)number12
noneLabel是否隐藏标签booleanfalse
placeholder输入框占位文本string-
disabled是否禁用boolean/Functionfalse
size输入框尺寸string-
required是否必填booleanfalse
validator自定义校验方法Function-
isBlock是否展示按钮样式booleanfalse
inactiveValueswitch的状态为off时的值string/number/booleanfalse
activeValueswitch 状态为on时的值string/number/booleantrue
blockInactiveswitch的状态为off时展示内容stringN
blockActiveswitch 状态为on时展示内容stringY
showErrorTooltip是否展示错误提示booleantrue
changeFun当绑定值变化时触发的回调函数Function-
showFun是否展示的判断函数,返回一个booleanFunction-