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
| <template>
| <div class="textarea-wrapper">
| <a-textarea
| class="m-textarea"
| v-bind="$attrs"
| v-model="$attrs.value"
| @change="onChange"
| />
| <span class="m-count" v-if="showWordLimit"
| >{{ textLength
| }}<template v-if="$attrs.maxLength"
| >/{{ $attrs.maxLength }}</template
| ></span
| >
| </div>
| </template>
| <script>
| export default {
| props: {
| // 是否展示字数统计
| showWordLimit: {
| type: Boolean,
| default: false,
| }
| },
| // v-model处理
| model: {
| prop: "value",
| event: "change",
| },
| computed: {
| // 长度控制
| textLength() {
|
| return (this.$attrs.value || "").length;
| },
| },
| methods: {
| onChange(e) {
| // v-model 回调函数
| this.$emit("change", e.target.value);
| },
| },
| };
| </script>
| <style scoped>
| .textarea-wrapper {
| position: relative;
| display: block;
| }
| .m-textarea {
| padding: 8px 12px;
| height: 100%;
| }
| .m-count {
| color: #808080;
| background: #fff;
| position: absolute;
| font-size: 12px;
| bottom: 8px;
| right: 12px;
| }
| </style>
|
|