ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
<script lang="ts" setup>
import { computed, ref, unref, watch } from 'vue';
 
import { useAttrs } from '@jnpf/hooks';
 
import { Input } from 'ant-design-vue';
 
import { textareaProps } from './props';
 
defineOptions({ inheritAttrs: false, name: 'JnpfTextarea' });
const props = defineProps(textareaProps);
const emit = defineEmits(['update:value', 'change']);
const InputTextArea = Input.TextArea;
const attrs = useAttrs({ excludeDefaultKeys: false });
const innerValue = ref('');
 
const getBindValue = computed(() => ({ ...unref(attrs), rows: props.rows }));
 
watch(
  () => unref(props.value),
  (val) => {
    setValue(val);
  },
  { immediate: true },
);
 
function setValue(value) {
  innerValue.value = value;
}
function onChange(e) {
  emit('update:value', e.target.value);
  emit('change', e.target.value);
}
</script>
 
<template>
  <InputTextArea v-bind="getBindValue" v-model:value="innerValue" @change="onChange">
    <template v-for="item in Object.keys($slots)" #[item]="data"><slot :name="item" v-bind="data || {}"></slot></template>
  </InputTextArea>
</template>