I need to sync an Object between a parent and child component in Vue using a <select> input but can't get the syntax correct.
component:
<template>
<div>
<select :value="condition" @change="$emit('update:condition', $event.target.value)">
<option v-for="variable in variable_options" :value="variable" :key="genUniqueKey(variable)">{{ variable.name }}</option>
</select>
</div>
</template>
<script>
module.exports = {
props: ['variable_options', 'condition']
}
</script>
I need something like a standard .sync modifier, but it doesn't seem to work on select inputs with objects:
<variable-select :variable_options="application_questions" :condition.sync="rule.condition">
</variable-select>
The condition is an object with id, name, and type attributes which come from the variable objects in the variable_options array. I've tried doing an initial_condition prop and then doing a v-model='selected_condition' on the select input like the docs recommend, but I don't know how to use that with a .sync modifier. Doing a :initial_condition.sync="rule.condition" isn't right.
Is there a way to pass the object attributes from the selected option in the child component, and update the parent component reactively? The data object's attributes are:
rule: {
condition: {
id: '',
name: '',
type: ''
}
}