Skip to content

Commit ccc31ee

Browse files
author
Tenny
committed
Squashed commit of the following:
commit 3c1c96a Author: Tenny <tenny.shu@foxmail.com> Date: Thu Sep 26 17:53:54 2024 +0800 fix(MdInput): 修复赋予初始值时显示异常
1 parent 4a8a621 commit ccc31ee

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/components/input/MdInput.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
:id="elId"
1313
ref="el"
1414
:type="htmlType"
15+
:inputmode="inputmode"
1516
:name="name"
1617
:placeholder="!focused ? '' : placeholder"
1718
@focus="handleInputFocus"
@@ -24,15 +25,14 @@
2425
</div>
2526
</template>
2627
<script setup lang="ts">
27-
import { ref, watch } from 'vue';
28+
import { ref, computed } from 'vue';
2829
import { random, isBlank } from 'ph-utils';
2930
3031
const el = ref<HTMLInputElement>();
3132
3233
const modelValue = defineModel<string | number>();
3334
3435
const focused = ref(false);
35-
const hasValue = ref(false);
3636
3737
const props = withDefaults(
3838
defineProps<{
@@ -41,8 +41,9 @@ const props = withDefaults(
4141
outline?: boolean;
4242
label?: string;
4343
placeholder?: string;
44-
htmlType?: 'text' | 'number' | 'password';
44+
htmlType?: 'text' | 'number' | 'password' | 'tel';
4545
name?: string;
46+
inputmode?: 'text' | 'numeric' | 'decimal' | 'tel';
4647
}>(),
4748
{
4849
outline: false,
@@ -68,8 +69,8 @@ function handleInputBlur() {
6869
focused.value = false;
6970
}
7071
71-
watch(modelValue, (v) => {
72-
hasValue.value = isBlank(v) ? false : true;
72+
const hasValue = computed(() => {
73+
return isBlank(modelValue.value as string) ? false : true;
7374
});
7475
7576
defineExpose({

0 commit comments

Comments
 (0)