我有一個作業選擇框,它正在將選定的值發送到更改事件的方法,但我有一個問題:
假設我也想cat_id在選擇時發送值(以便我可以在被呼叫的方法中構建一個與 cat_id 和日期相關的物件),是否有一種方法可以發送該 cat_id 或任何其他資料?選擇框更改事件?
var vm =
new Vue({
el: "#app",
props: {
},
data: {
testing_dates:['2021-11-29', '2021-11-30'],
cat_id: [123]
},
methods: {
testChange(event){
console.log(event.target.value);
},
},
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<li>Category ID: {{ cat_id }}</li>
<li style="list-style: none;">
<select style="width: auto;" @change="testChange($event)">
<option selected disabled>Options</option>
<option v-for="date in testing_dates" :value="date">{{ date }}</option>
</select>
</li>
</div>
uj5u.com熱心網友回復:
您可以傳遞另一個引數:
@change="testChange($event, cat_id)"
testChange(event, catId){
console.log(event.target.value, catId);
}
或者在函式內部訪問它:
testChange(event){
console.log(event.target.value, this.cat_id);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/365185.html
標籤:javascript Vue.js
上一篇:MUI5不使用jest-SyntaxError:不能在模塊外使用import陳述句
下一篇:React應該渲染多少次
