Answer the question
In order to leave comments, you need to log in
How to modify the code in VUE so that linked lists via v-model display the parameter immediately?
Good afternoon.
Link to code
If the select does not use v-model, then the first option is selected by default and displayed in the list.
If you add a dependency using v-model, then the field becomes empty.
Well, as a result, I would like to display the information as in the screenshot.
Answer the question
In order to leave comments, you need to log in
created() {
this.chooseChild = Object.values(this.parent)[0];
this.chooseS = Object.values(this.chooseChild)[0];
this.showinfo = Object.values(this.chooseS)[0];
},
data: () => ({
selectedValues: [],
...
computed: {
selectData() {
const options = [];
let { items } = this;
while (items instanceof Object) {
options.push(Object.keys(items));
items = items[this.selectedValues[options.length - 1]];
}
return {
options,
result: items || null,
};
},
},
<div>
<select
v-for="(options, i) in selectData.options"
v-model="selectedValues[i]"
@input="selectedValues.length = i"
>
<option v-for="n in options">{{ n }}</option>
</select>
</div>
<div>SELECTED: <b>{{ selectData.result || '< NONE >' }}</b></div>
created() {
let { items } = this;
while (items instanceof Object) {
const key = Object.keys(items)[0];
this.selectedValues.push(key);
items = items[key];
}
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question