input-length.vue
1.55 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<template>
<div class="input-length">
<Input
type="textarea"
:rows="rows"
:placeholder="placeholder"
:maxlength="maxlength"
:class="{'input-ele': true}"
:value="currentValue"
@input="inputEvent"></Input>
<p class="input-txt">
<span>{{txtMsg}}</span>
</p>
</div>
</template>
<script>
export default {
name: 'input-length',
props: {
value: {
type: [String, Number],
default: ''
},
rows: {
type: Number,
default: 5
},
placeholder: {
type: String,
default: '请输入文字内容'
},
maxlength: {
type: Number,
default: 250
}
},
computed: {
txtMsg() {
let num = this.maxlength - this.currentValue.length;
return `还能输${num >= 0 ? num : 0}个字`;
}
},
data() {
return {
currentValue: this.value
};
},
methods: {
inputEvent(val) {
this.currentValue = val;
this.$emit('input', val);
}
},
wacth: {
value(val) {
this.currentValue = val;
}
}
};
</script>
<style lang="scss" scoped>
.input-length {
width: 100%;
.input-ele {
width: 100%;
}
.input-txt {
text-align: right;
font-size: 12px;
margin-top: 2px;
span {
color: #999;
}
}
}
</style>