• This repository has been archived on 21/Mar/2023
  • Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

select2 component in vue.

[archived]Vue Select2 Component

This project is archived and no longer maintained.

This project was generated with Vue cli version 2.9.1.

Instructions

This project is built for showing how to use v-select2-component.

If you want to use it in Vue 3.0, check vue3-select2-component.

v-select2-component

Source code in: https://github.com/godbasin/vue-select2/tree/npm-publish-code.

Related Versions

Vue-Select2-Component is baseed on these plugins and libs(version):

How to use


Install

// npm install
npm install v-select2-component --save

Use as component

  1. import as global component.
// import Select2Component
import Select2 from 'v-select2-component';

Vue.component('Select2', Select2);
new Vue({
	// ...
})
  1. import into a single component.
// import Select2Component
import Select2 from 'v-select2-component';

<template>
  <div>
    <Select2 v-model="myValue" :options="myOptions" :settings="{ settingOption: value, settingOption: value }" @change="myChangeEvent($event)" @select="mySelectEvent($event)" />
    <h4>Value: {{ myValue }}</h4>
  </div>
</template>
<script>
export default {
    // declare Select2Component
    components: {Select2},
    data() {
        return {
            myValue: '',
            myOptions: ['op1', 'op2', 'op3'] // or [{id: key, text: value}, {id: key, text: value}]
        }
    },
    methods: {
        myChangeEvent(val){
            console.log(val);
        },
        mySelectEvent({id, text}){
            console.log({id, text})
        }
    }
}
</script>

Options

  • options: option[]
    • select options for select2
    • option: {id: key, text: value} or string
  • v-model: option value that is selected
    • id or string while multiple is disable
    • id[] or string[] while multiple is enable
  • disabled
    • if select is disabled
  • settings
    • configurable settings, see Select2 options API
    • setting: { settingOption: value, settingOption: value }

Events

  • change
    • triggered when option selected change
    • return value
    • parmas: same with v-model
  • select
    • triggered when option selected
    • parmas: option({id: value, text: key, selected: ifSelected} or string)
  • open
    • triggered whenever the dropdown is opened
  • close
    • triggered whenever the dropdown is closed
  • clear
    • triggered whenever the dropdown is cleared
  • more events refer to select2 events

More Repositories

1

godbasin.github.io

被删前端博客--喜欢请star
HTML
2,099
star
2

vue-ebook

《深入理解Vue.js实战》- 介绍Vue.js框架的出现、设计和使用,结合实战让读者更深入理解Vue.js框架,掌握使用方法。
Shell
1,004
star
3

front-end-playground

被删和阿猪的前端游乐场!!快来一起撸猫一起学习前端吧~
HTML
669
star
4

wxapp-typescript-demo

小程序 typescript 最佳实践 demo
TypeScript
194
star
5

front-end-book

《前端的进击》pdf 纪念版
42
star
6

5-minutes-help

我们需要一个更美好的世界
26
star
7

video-to-gif

Convert video to gif using ffmpegWasm
TypeScript
22
star
8

watch-behavior

小程序自定义组件扩展 behavior, watch 属性实现
JavaScript
19
star
9

angular-select2

select2 in angular(>=2.0-release).
TypeScript
15
star
10

box2djs-tutorial

box2djs-tutorial
JavaScript
14
star
11

vue-multi-pages

一个使用Webpack管理多页面的Vue Demo
JavaScript
12
star
12

deleted-tv-station

存放被删在 B 站前端视频相关的 PPT 分享
9
star
13

vue-element-demo

用vue+element快速拼接页面教程+代码示例
Vue
9
star
14

angular2-form-schame

Generate forms from a JSON schema, with Angular(v2.0+)!
TypeScript
5
star
15

godbasin

4
star
16

angular-form-component

angular form components in angular(>=2.0-release).
TypeScript
3
star
17

kitty-wxapp

吸猫小程序,云开发demo
JavaScript
3
star
18

cyclejs-demo

Cycle.js demo built with webpack
CSS
2
star
19

wxapp-ts-cli

小程序 typescript DEMO 脚手架
JavaScript
2
star
20

d3-tree-demo

A D3.js Tree demo.
HTML
2
star
21

angular-custom-app

Angular表单列表自定义/An angular app for setting custom form/form list/app.
CSS
1
star