# Number数字输入框
# 基础用法
通过将type
属性的值指定为number
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '输入框',
prop: 'input',
type: 'input'
},
{
label: '输入框',
prop: 'input1'
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 默认值
value
属性可以提供一个初始化的默认值
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '输入框',
prop: 'input',
value: '默认值'
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 禁用状态
disabled
属性接受一个Boolean,设置为true
即可禁用整个组件
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'num',
type: 'number',
disabled: true
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 最大值最小值
如果你只需要控制数值在某一范围内,可以设置min
属性和max
属性,不设置min
和max
时,最小值为 0
。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'num',
min: 1,
max: 2,
type: 'number'
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 步数
设置step
属性可以控制步长,接受一个Number
。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'num',
type: 'number',
step: 2,
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 严格步数
stepStrictly
属性接受一个Boolean
。如果这个属性被设置为true
,则只能输入步数的倍数。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'num',
type: 'number',
step: 2,
stepStrictly: true,
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 隐藏控制器
设置controls
属性是否使用控制按钮。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [{
label: '数字输入框',
prop: 'num',
type: 'number',
controls: false,
}]
}
}
}
}
</script>
显示代码复制代码复制代码
# 尺寸
可通过size
属性指定输入框的尺寸,默认为small
,还提供了large
,small
和mini
三种尺寸。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'input',
type: 'number',
size: 'large',
},
{
label: '数字输入框',
prop: 'input1',
type: 'number'
},
{
label: '数字输入框',
prop: 'input2',
type: 'number',
size: 'mini'
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 精度
设置precision
属性可以控制数值精度,接收一个Number
。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'num',
type: 'number',
precision: 2,
}
]
}
}
}
}
</script>
显示代码复制代码复制代码
# 按钮位置
设置 controlsPosition
属性可以控制按钮位置。
<template>
<avue-form :option="option"></avue-form>
</template>
<script>
export default {
data () {
return {
option: {
column: [
{
label: '数字输入框',
prop: 'num',
controlsPosition: '',
type: 'number'
}
]
}
}
}
}
</script>
显示代码复制代码复制代码