简体   繁体   English

将保存的电话号码绑定到 vue tel 输入以进行编辑

[英]Binding saved phone number to vue tel input for the purpose of editing

I am using vue-tel-input for entering a phone number.我正在使用 vue-tel-input 输入电话号码。

Phone number entry电话号码输入

<vue-tel-input
    v-model="phonenumber"
    @validate="telValidate"
></vue-tel-input>

Method to check it is valid:检查它是否有效的方法:

telValidate(telnumber) {
    this.validatedphonenumber = telnumber.number;
    this.validphonenumber = telnumber.valid;
},

Method to update phone number:更新电话号码的方法:

this.$axios.put("users/" + this.accountId, {
    phonenumber: this.validatedphonenumber
});

So this will update the user with the complete telephone number as a string such as "+447766554433"因此,这将使用完整的电话号码作为字符串更新用户,例如“+447766554433”

I am now trying to display this saved string in a vue-tel-input for the case of editing it.我现在正试图在 vue-tel-input 中显示这个保存的字符串,以便编辑它。 My questions are:我的问题是:

Firstly how do I bind the saved value to the vue-tel-input?首先,如何将保存的值绑定到 vue-tel-input?

Secondly am I right in thinking that I would have to save the countryCallingCode and the nationalNumber from the number object sperately or is there way of extracting the two parts from the single stored value?其次,我认为我必须从数字 object 中保存 countryCallingCode 和 nationalNumber 是否正确,或者有没有办法从单个存储值中提取这两个部分?

Using vue-tel-input with autoformat :vue-tel-inputautoformat一起使用:

 new Vue({ el: "#app", data() { return { phonenumber: null, validNumber: '', } }, methods: { telValidate(telnumber) { if (telnumber.valid) { this.validNumber = telnumber.number } else { this.validNumber = '' } }, }, template: ` <div> INPUT:<br /> <vue-tel-input v-model="phonenumber" @validate="telValidate" autoformat:dropdownOptions="{ showFlags: false, showDialCodeInSelection: true, }" /> <hr> EDIT:<br /> <vue-tel-input v-model="validNumber" autoformat:dropdownOptions="{ showFlags: false, showDialCodeInSelection: true, }" /> </div> ` })
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue-tel-input@5.3.0/dist/vue-tel-input.umd.min.js"></script> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vue-tel-input@5.3.0/dist/vue-tel-input.min.css"> <div id="app"></div>

It seems to me that vue-tel-input is not really good at parsing phone numbers.在我看来, vue-tel-input并不擅长解析电话号码。 If you "feed" it with a formatted phone number, then it quite understands but doesn't really set itself up.如果你用一个格式化的电话号码“喂”它,那么它很能理解,但并没有真正设置好自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM