[英]How to submit “ vue-multiselect ” selected option - Vue.js
I have this form with two inputs, Options (multiselect) and Amount 我的表格有两个输入, 选项 (多选)和金额
I have managed to add Amount to new Form but I failed to add the selected option. 我设法将金额添加到新表单中,但是无法添加所选选项。
HTML HTML
<template>
<div class="container">
<form @submit.prevent="submitForm" @keydown="form.onKeydown($event)">
<h5 class="form-header">
Vue JS form - Laravel
</h5>
<div class="form-group row">
<label class="col-form-label col-sm-4" for=""> Options</label>
<div class="col-sm-8">
<multiselect
v-model="selected"
:options="options">
</multiselect>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-sm-4" for=""> amount</label>
<div class="col-sm-8">
<input v-model="form.amount" type="text" name="amount" class="form-control" >
</div>
</div>
<div class="form-buttons-w text-right">
<button class="btn btn-primary" type="submit">Save</button>
</div>
</form>
</div>
</template>
JS JS
<script>
export default {
data(){
return {
selected: null,
options: ['One', 'Two', 'Three'],
form: new Form({
amount : ''
})
}
},
methods : {
submitForm(){
this.form.post('api/transaction')
}
},
mounted() {
}
}
</script>
How can I get the selected option ( multiselect ) in submitted data ? 如何在提交的数据中获取选定的选项( multiselect )? The same way am getting entered amount.
以相同的方式获取金额。
You can do like this 你可以这样
<div class="form-group row">
<label class="col-form-label col-sm-4" for=""> Options</label>
<div class="col-sm-8">
<multiselect
v-model="form.selected"
:options="options">
</multiselect>
</div>
</div>
<script>
export default {
data(){
return {
selected: null,
options: ['One', 'Two', 'Three'],
form: new Form({
amount : '',
selected:[],
})
}
},
methods : {
submitForm(){
this.form.post('api/transaction')
}
},
mounted() {
}
} </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.