【问题标题】:How can I combine vue tel input with input text vuetify?如何将 vue tel 输入与输入文本 vuetify 结合起来?
【发布时间】:2019-11-10 11:23:17
【问题描述】:

我的代码是这样的:

<v-row>        
    <v-col cols="12" sm="6" md="3">
    <v-text-field
        label="Phone"
        outlined 
        dense
    ></v-text-field>
    </v-col>
    <v-col cols="12" sm="6" md="3">
    <vue-tel-input v-model="phone"></vue-tel-input>
    </v-col>
</v-row>

我的代码笔是这样的:https://codepen.io/positivethinking639/pen/qBBKYON?&editable=true&editors=101

我想把它组合成这样:

蓝色标志取自 vue tel 输入。旁边的文本字段取自 vuetify 组件

如何像上图那样将 2 个不同的组件合二为一?

【问题讨论】:

  • 快速浏览一下文档似乎表明提供了input 事件,尝试捕获该事件并查看国家代码是否存在。
  • 请提及有需要 npmed 或 yarned 的包

标签: vue.js vuejs2 vue-component vuetify.js


【解决方案1】:

是的,可以在下拉菜单旁边设置国家代码

这里是工作代码笔:https://codepen.io/chansv/pen/pooZJey?editors=1010

<div id="app">
  <v-app id="inspire">
    <v-form>
      <v-container>
        <v-row>        
          <v-col cols="12" sm="6" md="3">
            <v-text-field
              label="Phone"
              outlined 
              dense
            ></v-text-field>
          </v-col>
          <v-col cols="12" sm="6" md="3">
            <vue-tel-input v-model="phone" @country-changed="countrySelected">
              <template v-slot:arrow-icon>
                <v-icon>arrow_drop_down</v-icon>
                <strong>+{{countryCode}}</strong>
               </template>
            </vue-tel-input>
          </v-col>
        </v-row>
      </v-container>
    </v-form>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
    data() {
      return {
        phone: null,
       countryCode: null,
      }
    },
    methods: {
  countrySelected(val) {
    this.countryCode = val.dialCode;
  }
}
})

【讨论】:

  • 这是一个看起来很漂亮的 hack,但是除了国家下拉列表之外,您失去了所有功能。 validCharactersOnly 和格式化等有用的选项丢失了。
猜你喜欢
  • 2018-05-30
  • 2017-05-22
  • 1970-01-01
  • 2020-02-03
  • 1970-01-01
  • 1970-01-01
  • 2020-07-07
  • 2014-12-29
  • 1970-01-01
相关资源
最近更新 更多