iku*_*ris 2 javascript vue.js vue-component vuejs2 vue-multiselect
我想参数传递到@select事件功能Vue.js
HTML
<template>
<div class="container">
<div v-for="(billItem, k) in billItems" :key="k" >
<div class="form-group row">
<label class="col-form-label col-sm-3" for=""> Products</label>
<div class="col-sm-3">
<div class="form-group">
<label for="">Product</label>
<multiselect
v-model="billItem.billItem_selectedGood"
:options="productOptions"
:close-on-select="true"
:clear-on-select="false"
:hide-selected="true"
:preserve-search="true"
placeholder="Select Product"
label="name"
track-by="name"
:preselect-first="false"
id="example"
@select="onSelect_selectedGood"
>
</multiselect>
</div>
</div>
</div>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
JS
<script>
export default {
data(){
return {
form: new Form({
})
}
},
methods : {
onSelect_selectedGood( option, id) {
console.log("onSelect_selectedGood");
console.log(option);
}
},
mounted() {
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的问题:如何将billItem传递给onSelect_selectedGood以便我可以在函数内部访问它。
像
@select="onSelect_selectedGood(billItem)"然后实现这样的功能onSelect_selectedGood( billItem, option, id)
让我知道如何实现它。
你可以简单地这样做:
@select="onSelect_selectedGood($event,billItem)"
Run Code Online (Sandbox Code Playgroud)
并在您的方法中:
methods : {
onSelect_selectedGood( selectedOption,billItem) {
console.log( selectedOption,billItem);
},
}
Run Code Online (Sandbox Code Playgroud)
传递的参数是$event它是selectedOption和billItem。