Number 数字输入框
通过鼠标或键盘,输入范围内的数值。
代码演示
<template>
<div>
<v-formly-v3 ref="form" v-model="formData" :meta="meta"> </v-formly-v3>
<div class="btns">
<el-button type="danger" @click="clear"> 重置 </el-button>
<el-button type="primary" @click="submit"> 提交 </el-button>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, toRaw, unref } from "vue";
import type VFormly from "@/element-plus/ElFormly.vue";
const form = ref<null | InstanceType<typeof VFormly>>(null);
const meta = {
type: "object",
properties: {
number1: {
type: "number",
title: "基础用法",
minimum: 1,
maximum: 10,
default: 1,
ui: {
showRequired: true,
change: (curVal: any, oldVal: any) => console.log(curVal, oldVal),
},
},
number2: {
type: "number",
title: "禁用状态",
default: 1,
readOnly: true,
},
number3: {
type: "number",
title: "步进",
default: 5,
ui: {
step: 2,
},
},
number4: {
type: "number",
title: "严格步进",
default: 2,
ui: {
step: 2,
stepStrictly: true,
},
},
number5: {
type: "number",
title: "精度",
default: 1,
ui: {
step: 0.1,
maximum: 10,
precision: 2,
},
},
number6_1: {
type: "number",
title: "不同的输入框尺寸",
default: 1,
ui: {
size: "large",
grid: {
span: 8,
},
},
},
number6_2: {
type: "number",
title: "不同的输入框尺寸",
default: 2,
ui: {
grid: {
span: 8,
},
},
},
number6_3: {
type: "number",
title: "不同的输入框尺寸",
default: 3,
ui: {
size: "small",
grid: {
span: 8,
},
},
},
number7: {
type: "number",
title: "按钮位置",
default: 1,
minimum: 1,
maximum: 10,
ui: {
controlsPosition: "right",
},
},
},
required: ["number1"],
};
let formData: any = ref({});
function clear() {
formData.value = null;
}
async function submit() {
let valid = await (form.value as any).validate();
if (valid) {
console.log(toRaw(unref(formData)));
}
}
</script>
<style scoped></style>
复制
API
我们只列出属性中不一致的或新添加的,一致的地方请参考 具体组件库 文档
meta 属性
成员 | 说明 | 类型 | 默认值 |
---|---|---|---|
[minimum] | 最小值 | number | - |
[exclusiveMinimum] | 约束是否包括 minimum 值,true 表示排除 minimum 值 | boolean | - |
[maximum] | 最大值 | number | - |
[exclusiveMaximum] | 约束是否包括 maximum 值,true 表示排除 maximum 值 | boolean | - |
[multipleOf] | 倍数 | number | 1 |
meta.ui 属性(antdv)
成员 | 说明 | 类型 | 默认值 |
---|---|---|---|
[slotNameOfAddonAfter] | 带标签的 input,设置后置标签,slot 名称 | string | 1 |
[slotNameOfAddonBefore] | 带标签的 input,设置前置标签,slot 名称 | string | 1 |
[slotNameOfPrefix] | 带有前缀图标的 input,slot 名称 | string | 1 |
@change | 变化回调 | Function(value: number | string) | - |
meta.ui 属性(element)
成员 | 说明 | 类型 | 默认值 |
---|---|---|---|
@change | 绑定值被改变时触发 | (currentValue: number, oldValue: number) | - |