import { ref, watch, onMounted } from 'vue'; export function useAutoResizeTextarea(textareaRef: any, text: any) { const adjustHeight = () => { const textarea = textareaRef.value.ref; textarea.style.height = 'auto'; // 重置高度 textarea.style.height = `${textarea.scrollHeight}px`; // 设置新高度 textarea.style['max-height'] = '240px'; textarea.style['min-height'] = '54px'; }; watch(text, (newVal) => { if (newVal === '') { textareaRef.value.ref.style.height = '54px'; return; } adjustHeight(); }); onMounted(() => { adjustHeight(); // 初始化时调整高度 }); }