我有一個包含檔案型別的下拉串列,我需要將所選型別存盤在資料屬性中,特別是 type.name ,以便我可以在子組件中參考它。但是,我的選擇沒有被存盤。我這樣做是錯誤的嗎?
預期結果: type.name 在資料變數中可供我使用。
<b-select
:v-model="documentType" >
<option
v-for="type in group.documentTypes"
:key="type.id"
:value="type.id"
:v-model="selected"
>
{{(type.name)}}
</option>
</b-select>
data() {
return {
waiting: {},
timer: null,
selected: ''
}
},
uj5u.com熱心網友回復:
只需將您v-model的select-tag. 使用 ,input-event您可以將您的選擇傳遞給methods。
從這里更新:在那里您可以使用您選擇的名稱并將其傳遞給您child.vue或做任何您想做的事情。
但請注意 - 不要:v-model只寫它v-model!
代碼
模板
<select v-model="selected_DT" @input="storeSelect(selected_DT)>
<option v-for="type in documentTypes" :key="type.id">
{{type.name}}
</option>
</select>
腳本:
data() {
return {
selected_DT: null,
documentTypes: [
{"id": 1, "name": "Test1"},
{"id": 2, "name": "Test2"},
{"id": 3, "name": "Test3"},
]
}
},
methods: {
storeSelect(selected_DT) {
console.log(selected_DT) //it's selected name you can pass to your child.vue
}
},
uj5u.com熱心網友回復:
您非常接近,但您v-model需要將其放在selecthtml 元素上。Then when one of the options are selected the value of the option will be passed to it
<select v-model="selected">
<option
v-for="type in group.documentTypes"
:key="type.id"
:value="type.id">
{{type.name}}
</option>
</select>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/397816.html
