0

I have a select where I am trying to set the :selected value to data from my server on page load. All the data is accessible but I am not sure what I am missing. My prop customer is an object that is passed in from the parent and comes from the backend. The value of customer.state is the abbreviated state , so "CA" for example. I tried doing :selected="this.customer.state" but that didn't work either.

data() {
    return {
        this.states = [
             {text: "California", value: "CA"},
             {text: "New Jersey", value: "NJ"},
             //etc
        ],
    }
},
props: {
    customer: {type: Object}
}


<select name="state" autocomplete="address-level1" @change="optionDropdown">
    <option v-for="x in optionsReturned" :value="x.value" :selected="???">
      {{ x.text }}
    </option>
</select>

1 Answer 1

1

value of selected must be true when the currently looped option is equal to customer's state (and false otherwise): :selected="customer.state === x.value"

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.