From 12c6f51d841e80bab7089725e63a034dbe6a294f Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期日, 11 一月 2026 21:57:45 +0800
Subject: [PATCH] 修改了代码
---
src/main.js | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/src/main.js b/src/main.js
index 32aeb90..e4738ac 100644
--- a/src/main.js
+++ b/src/main.js
@@ -62,7 +62,43 @@
Vue.use(directive)
Vue.use(plugins)
DictData.install()
+// 鍒涘缓涓�涓嚜瀹氫箟鎸囦护
+Vue.directive('auto-height', {
+ bind(el, binding) {
+ const minRows = binding.value?.minRows || 1;
+ const maxRows = binding.value?.maxRows || 10;
+ const resize = () => {
+ // 閲嶇疆楂樺害
+ el.style.height = 'auto';
+
+ // 鑾峰彇鍐呭楂樺害
+ const scrollHeight = el.scrollHeight;
+ const lineHeight = parseInt(getComputedStyle(el).lineHeight);
+
+ // 璁$畻闇�瑕佺殑琛屾暟
+ let rows = Math.floor(scrollHeight / lineHeight);
+ rows = Math.max(minRows, Math.min(rows, maxRows));
+
+ // 璁剧疆琛屾暟
+ el.setAttribute('rows', rows);
+ el.style.height = `${rows * lineHeight}px`;
+ };
+
+ // 鐩戝惉杈撳叆浜嬩欢
+ el.addEventListener('input', resize);
+ // 鍒濆鍖栨椂璋冩暣涓�娆�
+ resize();
+
+ // 淇濆瓨resize鍑芥暟浠ヤ究鍗歌浇
+ el._autoHeightResize = resize;
+ },
+
+ unbind(el) {
+ el.removeEventListener('input', el._autoHeightResize);
+ delete el._autoHeightResize;
+ }
+});
/**
* If you don't want to use mock-server
* you want to use MockJs for mock api
--
Gitblit v1.9.1