我有v-for一個v-for. 單擊我的選擇后,dropdown-item我將我的資料傳遞給我的methods- 當然,這很好用。
但是現在我需要itemDropdown.ID在我的方法中的另一個函式中精確...
我是否必須將資料從一個方法傳遞到另一個方法,或者我該如何解決?
謝謝你!
<div v-for="(item, index) in json" :key="index">
<b-dropdown text="Selection" right>
<b-dropdown-item v-for="(itemDropdown, indexDropdown) in json2" :key="indexDropdown" @click="inputDropdown(itemDropdown.ID)">{{itemDropdown.Name}}</b-dropdown-item>
</b-dropdown>
</div>
methods: {
inputDropdown(ID) {
//Some code
},
anotherFunction(here I need this itemDropdown.ID as well!)
//Do some code too
}
}
uj5u.com熱心網友回復:
我認為最好撰寫一些這樣的處理程式方法,您也可以使用其他方法擴展用法。
<div v-for="(item, index) in json" :key="index">
<b-dropdown text="Selection" right>
<b-dropdown-item v-for="(itemDropdown, indexDropdown) in json2" :key="indexDropdown" @click="dropdownClickHandler(itemDropdown.ID)">{{itemDropdown.Name}}</b-dropdown-item>
</b-dropdown>
</div>
我認為在這樣的用法中它會更具可讀性。
methods: {
dropdownClickHandler(ID) {
this.inputDropdown(ID);
this.anotherFunction(ID);
},
inputDropdown(ID) {
//Some code
},
anotherFunction(ID)
// Some code
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/328305.html
