From f9398ce73a1bccff71218117ae963ea2ecd6809b Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Thu, 24 Mar 2022 12:16:04 +0800 Subject: [PATCH] 优化跨页面数据传递 --- forms/input/CInput.vue | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 38 insertions(+), 11 deletions(-) diff --git a/forms/input/CInput.vue b/forms/input/CInput.vue index c6f16c8..74d986e 100644 --- a/forms/input/CInput.vue +++ b/forms/input/CInput.vue @@ -4,18 +4,28 @@ */ <template> - <AtInput - :name="itemRes.name" - :title="itemRes.label" - :type="type" - :placeholder="placeholder" - :required="itemRes.required" - :error="itemRes.error" - :value="itemRes.formData[itemRes.name]" - :onChange="evt=>itemRes.onChange(evt)" + <view + class="c-input" + :class="unit?'c-input-unit':''" > - <slot /> - </AtInput> + <AtInput + :name="itemRes.name" + :title="itemRes.label" + :type="type" + :placeholder="placeholder" + :required="itemRes.required" + :error="itemRes.error" + :cursorSpacing="0" + :value="value" + :onChange="evt => hanldeChange(evt)" + > + <slot v-if="!unit" /> + <text + class="c-input-unit-text" + v-if="unit" + >{{unit}}</text> + </AtInput> + </view> </template> <script> @@ -34,6 +44,23 @@ type: String, // 占位提示 placeholder: String, + // 输入框单位 + unit: String, + }, + computed: { + value() { + return (this.itemRes.formData[this.itemRes.name] || '').replace( + /[\n\r]/g, + '' + ); + }, + }, + methods: { + hanldeChange(evt) { + // 小程序中,可以粘贴换行符进来 + const changeValue = (evt || '').replace(/[\n\r]/g, ''); + this.itemRes.onChange(changeValue); + }, }, mounted() {}, }; -- Gitblit v1.9.1