How to make a proper emit of the modelValue with vue3 using props?

1k Views Asked by At

I'm expecting to pass the $event.target.value from the child compoenent first input to the optionsSkin key of the the parent component newSettings object and from the second input to parent's newSettings object - second key - optionsLeg. How can I bind each input to the inner object key ?

    // Parent
    <template>
        <ChartSettings :default="chartSettings" :modelValue="newSettings" />
    </template>

    <script>
    export default {
      data() {
        return {
          newSettings: {
            optionsSkin: '',
            optionsLeg: []
          }
        }
      }
      components: {
        ChartSettings,
      },
    };
    </script>

    // Child
    <q-option-group
      :options="settings.optionsSkin"
      type="radio"
      @input="$emit('update:modelValue', $event.target.value)"
    />
    <q-option-group
      :options="settings.optionsLeg"
      type="checkbox"
      :toggle-indeterminate="false"
      @input="$emit('update:modelValue', $event.target.value)"
    />

    <script>
    export default {
      props: ['modelValue'],
    };
    </script>

1

There are 1 best solutions below