Skip to content

Commit

Permalink
fix(MdInput): 修复赋予初始值时显示异常
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenny committed Sep 26, 2024
1 parent 4a8a621 commit 3c1c96a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/components/input/MdInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
:id="elId"
ref="el"
:type="htmlType"
:inputmode="inputmode"
:name="name"
:placeholder="!focused ? '' : placeholder"
@focus="handleInputFocus"
Expand All @@ -24,15 +25,14 @@
</div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import { ref, computed } from 'vue';
import { random, isBlank } from 'ph-utils';
const el = ref<HTMLInputElement>();
const modelValue = defineModel<string | number>();
const focused = ref(false);
const hasValue = ref(false);
const props = withDefaults(
defineProps<{
Expand All @@ -41,8 +41,9 @@ const props = withDefaults(
outline?: boolean;
label?: string;
placeholder?: string;
htmlType?: 'text' | 'number' | 'password';
htmlType?: 'text' | 'number' | 'password' | 'tel';
name?: string;
inputmode?: 'text' | 'numeric' | 'decimal' | 'tel';
}>(),
{
outline: false,
Expand All @@ -68,8 +69,8 @@ function handleInputBlur() {
focused.value = false;
}
watch(modelValue, (v) => {
hasValue.value = isBlank(v) ? false : true;
const hasValue = computed(() => {
return isBlank(modelValue.value as string) ? false : true;
});
defineExpose({
Expand Down

0 comments on commit 3c1c96a

Please sign in to comment.