-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
App.vue
51 lines (45 loc) · 1.22 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script setup>
import { ref } from "vue";
import IntlTelInput from "../../src/intl-tel-input/IntlTelInputWithUtils.vue";
const errorMap = [
"Invalid number",
"Invalid country code",
"Too short",
"Too long",
"Invalid number",
];
const isValid = ref(null);
const number = ref(null);
const errorCode = ref(null);
const notice = ref(null);
const intlTelInputRef = ref(null);
const handleSetNumber = () => {
intlTelInputRef.value?.instance?.setNumber("+14155552671");
};
const handleSubmit = () => {
if (isValid.value) {
notice.value = `Valid number: ${number.value}`;
} else {
const errorMessage = errorMap[errorCode.value || 0] || "Invalid number";
notice.value = `Error: ${errorMessage}`;
}
};
</script>
<template>
<form>
<IntlTelInput
ref="intlTelInputRef"
@changeNumber="number = $event"
@changeValidity="isValid = $event"
@changeErrorCode="errorCode = $event"
:options="{
initialCountry: 'us',
}"
/>
<button class="button" type="button" @click="handleSetNumber">
Set Number
</button>
<button class="button" type="button" @click="handleSubmit">Validate</button>
<div v-if="notice" class="notice">{{ notice }}</div>
</form>
</template>