基本输入框

基本输入框
<template>
 <single-demo label="基本输入框">
   <y-input></y-input>
 </single-demo>
</template>

1
2
3
4
5
6

其他类型

文本输入框
密码输入框
长文本输入框
自动调整
自定义
<template>
 <single-demo label="文本输入框">
   <y-input></y-input>
 </single-demo>
 <single-demo label="密码输入框">
   <y-input type="password"></y-input>
 </single-demo>
 <single-demo label="长文本输入框">
   <y-input type="textarea"></y-input>
 </single-demo>
 <single-demo label="自动调整">
   <y-input type="textarea" autosize></y-input>
 </single-demo>
 <single-demo label="自定义">
   <y-input type="textarea" :autosize="autosizeConfig"></y-input>
 </single-demo>
</template>

<script>
import { defineComponent, reactive } from 'vue';

export default defineComponent({
 name: 'Type',

 setup() {
   const autosizeConfig = reactive({
     minRows: 3,
     maxRows: 6,
   });

   return {
     autosizeConfig,
   };
 },
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

不同尺寸

小尺寸
正常尺寸
大尺寸
<template>
 <single-demo label="小尺寸">
   <y-input size="small"></y-input>
 </single-demo>
 <single-demo label="正常尺寸">
   <y-input></y-input>
 </single-demo>
 <single-demo label="大尺寸">
   <y-input size="large"></y-input>
 </single-demo>
</template>

1
2
3
4
5
6
7
8
9
10
11
12

清空态

可清除
<template>
 <single-demo label="可清除">
   <y-input clearable></y-input>
 </single-demo>
</template>

1
2
3
4
5
6

禁用态

禁止输入
只读模式
<template>
 <single-demo label="禁止输入">
   <y-input disabled placeholder="disabled"></y-input>
 </single-demo>
 <single-demo label="只读模式">
   <y-input readonly placeholder="readonly"></y-input>
 </single-demo>
</template>

1
2
3
4
5
6
7
8
9

输入前缀/后缀

配置prefix label
UserName
配置prefix icon
配置prefix slot
用户名
配置suffix label
@baidu.com
配置suffix icon
配置suffix slot
RMB
<template>
 <single-demo label="配置prefix label">
   <y-input prefix-label="UserName"></y-input>
 </single-demo>
 <single-demo label="配置prefix icon">
   <y-input :prefix-icon="MaleIcon"></y-input>
 </single-demo>
 <single-demo label="配置prefix slot">
   <y-input><template v-slot:prefix>用户名</template></y-input>
 </single-demo>
 <single-demo label="配置suffix label">
   <y-input suffix-label="@baidu.com"></y-input>
 </single-demo>
 <single-demo label="配置suffix icon">
   <y-input :suffix-icon="SearchIcon"></y-input>
 </single-demo>
 <single-demo label="配置suffix slot">
   <y-input><template v-slot:suffix>RMB</template></y-input>
 </single-demo>
</template>

<script>
import { defineComponent } from 'vue';
import MaleIcon from './male.svg';
import SearchIcon from './search.svg';

export default defineComponent({
 name: 'PrefixAndSuffix',

 setup() {
   return {
     MaleIcon,
     SearchIcon,
   };
 },
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

数量限制

展示输入限制
0/300
最多300字符
0/300
<template>
 <single-demo label="展示输入限制">
   <y-input :maxlength="300" show-word-limit></y-input>
 </single-demo>
 <single-demo label="最多300字符">
   <y-input type="textarea" :maxlength="300" show-word-limit></y-input>
 </single-demo>
</template>

1
2
3
4
5
6
7
8
9

输入框提示

配置error message

校验失败,这是提示语句

配置help text

这是辅助文案,请在合适的位置使用

配置help slot
这是辅助文案,请在合适的位置使用
配置error message

校验失败,这是提示语句

配置help text

这是辅助文案,请在合适的位置使用

配置help slot
这是辅助文案,请在合适的位置使用
<template>
 <single-demo label="配置error message">
   <y-input error error-message="校验失败,这是提示语句"></y-input>
 </single-demo>
 <single-demo label="配置help text">
   <y-input help-text="这是辅助文案,请在合适的位置使用"></y-input>
 </single-demo>
 <single-demo label="配置help slot">
   <y-input><template v-slot:help>这是辅助文案,请在合适的位置使用</template></y-input>
 </single-demo>
 <single-demo label="配置error message">
   <y-input type="textarea" error error-message="校验失败,这是提示语句"></y-input>
 </single-demo>
 <single-demo label="配置help text">
   <y-input type="textarea" help-text="这是辅助文案,请在合适的位置使用"></y-input>
 </single-demo>
 <single-demo label="配置help slot">
   <y-input type="textarea"><template v-slot:help>这是辅助文案,请在合适的位置使用</template></y-input>
 </single-demo>
</template>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

校验

仅输入数字
自定义配置
<template>
 <single-demo label="仅输入数字">
   <y-input
     placeholder="Please input number"
     restriction="number">
   </y-input>
 </single-demo>
 <single-demo label="自定义配置">
   <y-input
     placeholder="Please input number"
     restriction-type="value"
     :restriction="restriction">
   </y-input>
 </single-demo>
</template>

<script>
import { defineComponent } from "vue";

export default defineComponent({
 name: "Restriction",

 setup() {
   const restriction = (val) =>{
     return /^.{1,3}$/.test(val);
   };

   return {
     restriction,
   };
 }
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

数字输入框

基础
配置精度
Input tip: value precision is 2
配置最值
Input tip: min value: 2, max value: 99.98, precision is 2
<template>
 <single-demo label="基础">
   <y-input v-model="value11" type="numeric"></y-input>
 </single-demo>
 <single-demo label="配置精度">
   <y-input v-model="value12" type="numeric" :precision="2">
     <template v-slot:help>Input tip: value precision is 2</template>
   </y-input>
 </single-demo>
 <single-demo label="配置最值">
   <y-input v-model="value13" type="numeric" :precision="2" :max="99.98" :min="2">
     <template v-slot:help>Input tip: min value: 2, max value: 99.98, precision is 2</template>
   </y-input>
 </single-demo>
</template>

<script>
import { defineComponent, reactive, toRefs } from 'vue';

export default defineComponent({
 name: 'Type',

 setup() {
   const state = reactive({
     value11: '',
     value12: '',
     value13: '',
   });

   return toRefs(state);
 },
});
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

分组

输入框组合
输入框组合
<template>
 <single-demo label="输入框组合">
   <y-input-group>
     <y-input style="width: 80px"></y-input>
     <y-input style="width: calc(100% - 80px)"></y-input>
   </y-input-group>
 </single-demo>
 <single-demo label="输入框组合">
   <y-input-group>
     <y-input style="width: 40%"></y-input>
     <y-input style="width: 60%"></y-input>
   </y-input-group>
 </single-demo>
</template>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

API

Input props

PropertyDescriptionTypeAccepted ValuesDefault
typethe type of inputStringnative type and textarea / numerictext
modelValuethe value of inputString--
placeholderthe placeholder of inputString--
namethe native name of inputString--
readonlythe native readonlyBoolean--
autofocusthe native autofocusBoolean--
autocompletethe native autocompleteBoolean--
formthe native formBoolean--
minlengththe native min lengthNumber--
maxlengththe native max lengthNumber--
sizethe size of inputStringlarge/normal/smallnormal
suffix-labelthe suffix label of inputString--
prefix-labelthe prefix label of inputString--
prefix-iconthe prefix icon, accepts svgString--
suffix-iconthe suffix icon, accepts svgString--
disabledwhether the input is disabledBoolean-false
clearablewhether the input in clearableBoolean-false
restrictionthe restriction of input. Only effective at inputEventString, Function, RegExpnumber-
restriction-typethe restriction type of input, when the type is input, it will only restrict the current input, when the type is value, it will restrict the whole valueStringvalue, inputinput
errorwhether the value of input is invalidBoolean-false
error-messagethe error message of inputString--
rowsthe native rows of textareaNumber--
minrowsthe min rows of textareaNumber--
maxrowsthe max rows of textareaNumber--
autosizewhether the textarea will auto adjust its sizeBoolean-false
lazythe same as v-model.lazyBoolean-false
help-textthe help message of inputString--
show-word-limitwhether show word limitBoolean-false
maxthe max value of number input, only works for type=numericNumber--
minthe min value of number input, only works for type=numericNumber--
precisionprecision of input value, only works for type=numericNumber--
is-roundwether use Number.toFixed or direct intercept, only works for type=numericBoolean-true(means direct intercept)
unicode-normalizedwhether to calculate the string by utf-16, instead of the default utf-8Boolean-false

Input slot All input slots and following

SlotDescription
prefixthe prefix label of input
suffixthe suffix label of input
errorthe error message of input
helpthe help message of input

Input events All native input events and following

EventDescriptionParameters
value-changethe change event of input valuethe value

InputGroup props

PropertyDescriptionTypeAccepted ValuesDefault
prepend-widththe width of prependNumber-120

InputGroup slot All input slots and following

SlotDescription
prependthe prepend of group
appendthe append of group