v-select2-multiple-component
v0.1.1
Published
Select 2 Multiple control for Vue
Downloads
709
Maintainers
Readme
v-select2-multiple-component
Select2 control with multiple select for Vue.
Dependencies libraries
V-Select2-Component is baseed on these plugins and libs(version):
- vue(>= 2.0-release)
- jQuery
- select2
- v-select2-component (the select2 component version but not support multiple select)
How to install & use
Install
// npm install
npm install v-select2-multiple-component --save
Use in component
- Import as global component (use everywhere):
// import Select2MultipleControl
import Select2MultipleControl from 'v-select2-multiple-component';
Vue.component('Select2MultipleControl', Select2);
new Vue({
// ...
})
- Import into a single component:
<template>
<div>
<select2-multiple-control v-model="myValue" :options="myOptions" @change="myChangeEvent($event)" @select="mySelectEvent($event)" />
<h4>Value: {{ myValue }}</h4>
</div>
</template>
<script>
import Select2MultipleControl from 'v-select2-multiple-component';
export default {
// declare Select2MultipleControl
components: {Select2MultipleControl},
data() {
return {
myValue: '',
myOptions: ['op1', 'op2', 'op3'] // or [{id: key, text: value}, {id: key, text: value}]
}
},
method: {
myChangeEvent(val){
console.log(val);
},
mySelectEvent({id, text}){
console.log({id, text})
}
}
}
</script>
Option settings
options
:option[]
- data source for select2
option
:{id: key, text: value}
orstring
v-model
: option values that is selectedid[]
orstring[]
change
- callback when option selected change
- return value
- parmas: same with
v-model
select
- callback when option selected
- parmas:
option
({id: value, text: key, selected: ifSelected}
orstring
)
disabled
- if select is disabled
settings
- configurable settings, see Select2 options API
setting
:{ settingOption: value, settingOption: value }
Final
Special thanks to godbasin for the non-multiselect select2.
Copyright © 2018 by Seth Phat Phat Tran Minh