vue-country-select
A Vue.js component implementing the select control used to select countries.
Demo
The demo page is HERE.
Requirements
- Vue.js
^1.0.24
- vue-select
^0.2.3
- vue-i18n-plugin
^0.2.2
This is optional.
Instllation
npm
$ npm install vue-country-select
bower
$ bower install vue-country-select
Usage
The HTML snippets are as follows:
Select country: Selected country: {{result}}
The Javascript snippets are as follows:
var Vue = ;var vm = el: "#app" components: "vue-country-select": data: result: null ;
Component Properties
model
The model bind to the control, which must be a two way binding variable.
Note that the value of model could be set to null
, and in that case the
selection will be set to nothing. Also, if the selection is set to nothing
(that is, the user delete the text in the input box of the selector), the
value of the model will be set to null
instead of an empty string.
searchable
The optional flag indicates whether to show the search box.
language
The optional code of language used by the select2 plugin.
The supported languages are exactly the same as the supported languages of the select2 plugin. In order to use the supported language, you must also include the corresponding "i18n" js file of the select2 plugin in your HTML file.
Note that the language code passed to this property could be a locale code
consists of a language code and a country code, e.g., "en-US"
. The component
will automatically convert the locale code to the language code supported by
the select2 plugin. Since some languages
have different variants in different country or region, e.g., "zh-CN"
for the
simplified Chinese and "zh-TW"
for the traditional Chinese, it's recommended
to use the locale code in the form of "[language]-[country]"
.
If this property is not set, and the vue-i18n
plugin is used, the component will use the language code $language
provided
by the vue-i18n plugin; otherwise, the
component will use the default value "en-US"
.
theme
The optional name of the theme of the select2
plugin. Default value is 'bootstrap'
.
Note that in order to use the bootstrap theme, you must include the CSS file from the select2-bootstrap-theme project. And it's very important that the above CSS file must be included AFTER the CSS file of the bootstrap.
The following is the correct order for including CSS files:
Check the demo page for details.
API
control
This property is a reference to the JQuery selection of the base select
control. It could be used to call the APIs of
select2 plugin. For example,
select.control.val(val)
will set the value of the select to the
specified value, where select
is the reference to the vue-country-select
component.
Localization
This component could use the vue-i18n plugin to localize the names of countries.
In order to localize this component, the localization files provided to the vue-i18n plugin must provide the following localization messages:
If no vue-i18n is used, or the localization file of the plugin does not provide the localization name of a country, the default English name will be used.
Some localization files could be found in the src/i18n
directory.
Data
The country list comes from http://data.okfn.org/data/core/country-list
Contributing
- Fork it !
- Create your top branch from
dev
:git branch my-new-topic origin/dev
- Commit your changes:
git commit -am 'Add some topic'
- Push to the branch:
git push origin my-new-topic
- Submit a pull request to
dev
branch ofHaixing-Hu/vue-country-select
repository !
Building and Testing
First you should install all depended NPM packages. The NPM packages are used for building and testing this package.
$ npm install
Then install all depended bower packages. The bower packages are depended by this packages.
$ bower install
Now you can build the project.
$ gulp build
The following command will test the project.
$ gulp test
The following command will perform the test and generate a coverage report.
$ gulp test:coverage
The following command will perform the test, generate a coverage report, and upload the coverage report to coveralls.io.
$ gulp test:coveralls
You can also run bower install
and gulp build
together with the following
command:
npm run build
Or run bower install
and gulp test:coveralls
together with the following
command:
npm run test