0

I have a custom select box.

<select-box :options="['Male', 'Female', ]"
            title="Gender"
            v-bind:value="selected"
            v-model="person.gender"
>
</select-box> 

The .vue code

<script>
    export default {
          props:['title', 'options'],
          data () {
            return {
              selected: this.title,
              dropdownVisible: false,
            }
          },
          methods: {
            toggleOptions() {
              this.dropdownVisible = !this.dropdownVisible
            },
            selectValue(option) {
              this.selected = option;
              this.toggleOptions();
            }
        }

        }

How can I bind the selected value directly to the model (person.gender)?

1 Answer 1

1

I assume that above .vue code belongs to select-box component.

Because I saw you use v-model, to bind value directly to v-model, you need to $emit inside children component.

You can change your selectValue function

selectValue(option) {
  this.selected = option;
  this.$emit('input', option);
  this.toggleOptions();
}
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.