admin管理员组文章数量:1310909
I am trying to pass parameter to @select event function in 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>
JS
<script>
export default {
data(){
return {
form: new Form({
})
}
},
methods : {
onSelect_selectedGood( option, id) {
console.log("onSelect_selectedGood");
console.log(option);
}
},
mounted() {
}
}
</script>
My Question: How can I pass billItem to onSelect_selectedGood so I can access it inside the function.
Something like
@select="onSelect_selectedGood(billItem)"
then implement the function like this onSelect_selectedGood( billItem, option, id)
Let me know how I can achieve it.
I am trying to pass parameter to @select event function in 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>
JS
<script>
export default {
data(){
return {
form: new Form({
})
}
},
methods : {
onSelect_selectedGood( option, id) {
console.log("onSelect_selectedGood");
console.log(option);
}
},
mounted() {
}
}
</script>
My Question: How can I pass billItem to onSelect_selectedGood so I can access it inside the function.
Something like
@select="onSelect_selectedGood(billItem)"
then implement the function like this onSelect_selectedGood( billItem, option, id)
Let me know how I can achieve it.
Share Improve this question edited Jul 17, 2020 at 19:45 Boussadjra Brahim 1 asked May 6, 2019 at 20:31 ikuchrisikuchris 1,1721 gold badge15 silver badges33 bronze badges 2- What library are you using here? – Ohgodwhy Commented May 6, 2019 at 20:41
- @Ohgodwhy am using this library vue-multiselect ( vue-multiselect.js ) – ikuchris Commented May 6, 2019 at 20:54
2 Answers
Reset to default 8You could do it simply like :
@select="onSelect_selectedGood($event,billItem)"
and in your methods :
methods : {
onSelect_selectedGood( selectedOption,billItem) {
console.log( selectedOption,billItem);
},
}
the passed parameters are the $event
which is the selectedOption
and billItem
.
If you want to access all billItem, option
and id
, you can create a custom input ponent:
CustomInput.vue
<template>
<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>
</template>
<script>
export default {
props: ['billItem'],
methods: {
onSelect_selectedGood( option, id) {
console.log("onSelect_selectedGood");
console.log(option);
console.log(this.billItem)
}
}
}
</script>
and then using it in your html:
<custom-input
:billItem="billItem"
/>
Because you passed billItem
as a prop, you can access it by this.billItem
in custom ponent.
本文标签: javascriptPass parameters to select of multiselect in VuejsvuemultiselectStack Overflow
版权声明:本文标题:javascript - Pass parameters to @select of multiselect in Vue.js - vue-multiselect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741865770a2401891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论