vue-country-code is a Vue 2 component designed for selecting country codes, typically integrated into forms for phone number inputs. It provides a customizable dropdown list of countries, their flags, and international dial codes. Developers can configure default selections, specify preferred or excluded countries, and enable/disable features like flag display or automatic country detection based on the user's IP address. Currently at version 1.1.3, the package appears to be in a maintenance state, leveraging established external libraries such as libphonenumber-js for robust telephone number parsing and validation, and ipinfo.io for initial country detection. Its core functionality is based on a fork of vue-tel-input, offering a stable but not actively feature-developing solution primarily for Vue 2 applications.
npm install vue-country-codeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to globally register and use the `vue-country-code` component within a Vue 2 application, including handling the `onSelect` event to capture country details and displaying them.
For Vue 3 projects, seek out a Vue 3-compatible country code picker component. If this component is essential, your application must remain on Vue 2.
Consider disabling IP-based fetching using `:disabledFetchingCountry="true"` and manually setting a `:defaultCountry` or providing a list of `:preferredCountries` to ensure predictable behavior.
Evaluate if the current feature set meets all your project's long-term requirements. For applications needing active development or cutting-edge features, consider the original `vue-tel-input` or other more actively maintained alternatives.
For better control and to avoid global conflicts, import the component locally into the specific Vue Single File Components (SFCs) where it is used, e.g., `import VueCountryCode from 'vue-country-code'; export default { components: { VueCountryCode } }`.Ensure `Vue.use(VueCountryCode)` is called in your application's entry point (e.g., `main.js`) for global registration, or explicitly include `VueCountryCode` in the `components` option of the Vue component where it's being used.
This package is a Vue 2 component and not compatible with Vue 3. You must either use this component in a Vue 2 project or find a Vue 3 compatible alternative.
Ensure the component with `ref="vcc"` is rendered and mounted before attempting to access its methods. Access `this.$refs.vcc` within a `mounted()` lifecycle hook or after a user interaction guarantees the component instance is available.