Dependent country state city Cascading dropdown using Vuejs

Dependent country state city Cascading dropdown using Vuejs

In this Post We Will Explain About is Dependent country state city Cascading dropdown using Vuejs With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Cascading dropdown in VueJS Example

In this post we will show you Best way to implement Vue Select | VueJS Select2 Component, hear for Cascading (Dependent) Country State City DropDownLists using vuejs with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating Cascading DropDownList In VueJS

In this Example,First of all Add or Inluce External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priorty set.After that Include your relavant CSS Class.

Also Read :  jquery $.inArray Method with Example

Include External Libs

vue.js

index.html

<body>
    <div id="liveapp"></div>
</body>

index.js

new Vue({
    el: '#liveapp',
    template: `
        <div class="cascading-dropdown">
            <div class="dropdown">
                <span>Live Continent:</span>
                <select v-model="menuSelected">
                    <option value="">Select a Live Continent</option>
                    <option v-for="(userCountry_obj, userCountry) in userplaces" :value="userCountry">{{userCountry}}</option>
                </select>
            </div>
            <div class="dropdown">
                <span>Country:</span>
                <select :disabled="userCountries.length == 0" v-model="selecteduserCountry">
                    <option value="">Select a USER Country</option>
                    <option v-for="(userCity_obj, userCity) in userCountries">{{userCity}}</option>
                </select>
            </div>
            <div class="dropdown">
                <span>City:</span>
                <select :disabled="userCities.length == 0" v-model="selecteduserCity">
                    <option value="">Select a City</option>
                    <option v-for="userCity in userCities">{{userCity}}</option>
                </select>
            </div>
        </div>
    `,
    data: function() {
        return {
            userplaces: {
                "Asia": {
                    "China": ["China 1", "China 2", "China 3", "China 4"],
                    "India": ["India 1", "India 2", "India 3", "India 4"],
                    "Japan": ["Japan 1", "Japan 2", "Japan 3", "Japan 4"],
                    "Singapore": ["Singapore 1"],
                    "Malaysia": ["Malaysia 1", "Malaysia 2", "Malaysia 3", "Malaysia 4"]
                },
                "Europe": {
                    "Germany": ["Germany 1", "Germany 2", "Germany 3", "Germany 4", "Germany 5", "Germany 6"],
                    "UK": ["UK 1", "UK 2", "UK 3", "UK 4"],
                    "France": ["France 1", "France 2", "France 3", "France 4"]
                }
            },
            userCountries: [],
            userCities: [],
            menuSelected: "",
            selecteduserCountry: "",
            selecteduserCity: ""
        }
    },
    watch: {
        menuSelected: function() {
            // Clear previously selected values
            this.userCountries = [];
            this.userCities = [];
            this.selecteduserCountry = "";
            this.selecteduserCity = "";
            // Populate list of userCountries in the second dropdown
            if (this.menuSelected.length > 0) {
                this.userCountries = this.userplaces[this.menuSelected]
            }
        },
        selecteduserCountry: function() {
            // Clear previously selected values
            this.userCities = [];
            this.selecteduserCity = "";
            // Now we have a continent and userCountry. Populate list of userCities in the third dropdown
            if (this.selecteduserCountry.length > 0) {
                this.userCities = this.userplaces[this.menuSelected][this.selecteduserCountry]
            }
        }
    }
})

style.css

.dropdown {
    margin: 12px 0;
    padding: 12px 0;
    border-bottom: 1px solid #3D3D3D;
}

.dropdown span {
    display:inline-block;
    width: 100px;
}

jsfiddle Example

Also Read :  Jquery $.grep() Multiple Conditions

You are Most welcome in my youtube Channel Please shubscibe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Dependent country state city dropdown using Vuejs And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Reply

avatar
  Subscribe  
Notify of