1

I have a json string which lists all of the countries, for example:

AC:"Ascension Island"
AD:"Andorra"
AE:"United Arab Emirates"
AF:"Afghanistan"
AG:"Antigua & Barbuda"

I am getting the value via a get request and assigning them to an array like so:

        axios.get('/countries')
            .then(response => {
                this.countries = response.data;
            })


    data: function () 
    {
        return {
            countries: [],

But when I am using the following, the page doesn't load and I do not get an error:

<select class="selectpicker" data-live-search="true" v-model="location" v-for="(value, key) in countries">  
    <option value="{{ key }}">{{ value }}</option>
</select>
1
  • Your response is an object where the two character country values are the properties? Commented Jun 25, 2017 at 0:02

2 Answers 2

1

You can do this in vue with

<select class="selectpicker" data-live-search="true" v-model="location">
    <option :value="key" v-text="value" v-for="(value, key) in countries"></option>
</select>

Note that whatever you put the v-for on is the element that will repeat in the DOM. In your example, it would have been creating multiple select tags

Sign up to request clarification or add additional context in comments.

Comments

0

Move v-for to option tag. Previous was same thing

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.