如何使用vue-tel-input的事件?

Abd*_*wzy 1 vue.js vuejs2

我已经安装了vue-tel-input组件并将其包含在内。我想使用链接中找到的验证事件!但我不能。如何在组件中使用它?

F3C*_*3CP 7

这些事件是常规的 vue 组件事件。您可以按照 vue 文档中的概述监听这些事件。 https://v2.vuejs.org/v2/guide/components.html#Listening-to-Child-Components-Events

例如,要使用 validate 事件,您需要向 vue-tel-input 组件添加一个监听器。

侦听器会自动将参数传递给您的方法。

// In your template
<vue-tel-input
  v-model="yourModel"
  @validate="yourValidationMethod"
/>

// In your component methods

yourValidationMethod: function ({ number, isValid, country }) {
    // Do stuff with the arguments passed by the vue-tel-input component
},
Run Code Online (Sandbox Code Playgroud)