帝国模板之家为广大用户提供专业、一站式建站服务。

网页特效

网页特效栏目收集了最全最新的前端网页插件,包括最流行的jQuery,Bootstrap,Js,Css,Vue等主流特效插件。

当前位置:首页 > 资源 > 网页特效 > 正文

Vue.js(vue-accessible-selects)下拉选择组件

帝国模板之家 2020-12-27 网页特效 评论

描述:

一个自定义,可访问,可搜索的select下拉组件,它支持多项选择。

使用方法

1.将组件导入Vue项目。

import { 
  // single selection
  SelectSingle, 
  // multiple selection
  SelectMulti, 
  // core
  SelectOption 
} from '@politico/vue-accessible-selects'

2.将单个和多个选择组件添加到模板。

<SelectSingle
  v-model="selectSingleValue"
  :options="myOptions"
  label="Single Select"
  :labelIsVisible="true"
  @select="handleSelectEvent"
/>
<SelectMulti
  v-model="selectMultiValues"
  :options="myOptions"
  label="Multiple Select"
  :labelIsVisible="true"
  placeholder="Placeholder"
  @select="handleSelectEvent"
  @remove="handleRemoveEvent"
  @searchChange="handleSearchChangeEvent"
/>

3.注册组件并定义要在选择中显示的数据。

const myOptions: SelectOption[] = [{
  label: 'Option 1',
  value: 'option1'
}, {
  label: 'Option 2',
  value: 'option2'
}, {
  label: 'Option 3',
  value: 'option3'
}]
export default Vue.extend({
  components: { SelectSingle, SelectMulti },
  data() {
    return {
      myOptions,
      selectSingleValue: {} as SelectOption,
      selectMultiValues: [] as SelectOption[]
    }
  },
  methods: {
    handleSelectEvent(selectedValue: SelectOption) {
      // do something
    },
    handleRemoveEvent(selectedValue: SelectOption) {
      // do something
    },
    handleSearchChangeEvent(inputValue: string) {
      // do something
    }
  }
})

4. 组件所有默认配置。

disabled: {
  type: Boolean,
  default: false
},
label: {
  type: String,
  required: true
},
loading: {
  type: Boolean,
  default: false
},
options: {
  type: Array as PropType<SelectOption[]>,
  required: true
},
labelIsVisible: {
  type: Boolean,
  required: false,
  default: true
},
placeholder: {
  type: String,
  required: false,
  default: () => null
},
/**
 * When using a slot to display each option in the select,
 * you'll want to pass in a way for the select to *search* for those options as a user types,
 * in order to accurately filter the available options
 * @example
 * ```
 * :optionLabelForSearching="a => a.label + '-' + a.value"
 * ```
 */
optionLabelForSearching: {
  type: Function as PropType<(option: SelectOption) => string>,
  required: false,
  default: null
},
displayPillsBelowInput: {
  type: Boolean,
  default: false
},
/**
 * By default, the list will be empty when either no options are passed in,
 * or a user has typed a string that doesn't match any of the options. 
 * If you'd like to display a messsage instead when that occurs, pass it in here
 */
noResultsMessage: {
  type: String,
  default: ''
},
/** Generally, there's no need to set this via a prop - it will be set automatically when using v-model */
values: {
  type: Array as PropType<SelectOption[]>,
  required: false,
  default: () => []
}
这世上无忧无虑的人,反而相对寿命会长点。

已有 位小伙伴发表了看法

欢迎 发表评论

  • 匿名发表

关于

帝国cms模板

网页插件

帝国模板之家 | www.moyouyouw.cn

本站所有模板/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系站长删除,谢谢! 寻找帝国cms模板首选帝国模板之家,用心做站,上线至今广受好评,值得信赖!

  • 交流群1:帝国cms交流群1
  • 交流群2:帝国cms交流群2
在线QQ 给我留言