npm 包 igroot-upgrade-select 使用教程

阅读时长 5 分钟读完

igroot-upgrade-select 是一款快速实现升级带有筛选与排序功能的下拉框组件的 npm 包。它基于 antd-select 组件,通过简单的配置即可开箱即用。本教程将详细介绍 igroot-upgrade-select 的使用方法,让你快速上手并开始使用。

安装

你可以使用 npm 安装 igroot-upgrade-select:

使用

基本使用

使用 igroot-upgrade-select 非常简单,只需要像使用 antd-select 组件一样引用它即可:

这样你就已经可以看到一个基本的 igroot-upgrade-select 组件了。

带有筛选的 igroot-upgrade-select

基本上,使用 igroot-upgrade-select 与 antd-select 相同。但是,igroot-upgrade-select 可以通过简单的配置来实现带有筛选功能的组件。示例代码如下:

-- -------------------- ---- -------
------ - ------------- - ---- ------------------------

----- ---------- - --
  ------ ----
  ------ ------
---
  ------ ----
  ------ ------
---
  ------ ----
  ------ ------
---
  ------ ----
  ------ ------
---

----- ------ - -
  -- -----
  ----------- ----------
  -- -----
  ---------------- --
    ------ ----
    ----- --------
  ---
    ------ ----
    ----- --------
  ---
--

--------------
  -----------------------
  -----------------------------------------------
  ---------------------
--
展开代码

在以上代码中,先定义了一份 dataSource 数据源,然后通过在 UpgradeSelect 组件中传入 dataSource prop 即可创建一个简单的下拉框组件。在中间,定义了一个 config 变量,它的 searchKeys 设置 label 属性用于筛选,而 advancementKeys 则是升级项的配置,指定了其名字和值。最后在 UpgradeSelect 嵌套一些 prop 来决定是否需要开启筛选和升级功能即可。

深入学习

UpgradeSelect 组件的 props

UpgradeSelect 还支持以下 props:

  • dataSource:下拉框的配置项列表
  • mode:单选 multiple - 多选 tags - 标签
  • allowClear:清除按钮
  • maxTagCount:最多显示的标签个数
  • maxTagPlaceholder:标签溢出显示的占位内容
  • showSearch:是否显示搜索框
  • tokenSeparators:多选模式下的分隔符
  • optionConfig:高级配置
  • isAdvancement:是否开启升级 Select
dataSource

dataSource 是下拉框的配置项列表,可以使用一个简单数组的方式来传递相关的数据项。

mode

下拉框组件的模式,支持的选项有 single(单选)、multiple(多选)和 tags(标签)。

allowClear

是否显示清除按钮。

maxTagCount

限定多选时最多显示的个数。

maxTagPlaceholder

如果超过了最大个数,溢出的标题显示。

showSearch

是否开启搜索框,如果开启需要在 optionConfig 中配置 searchKeys。

tokenSeparators

多选模式下的分隔符。

optionConfig

高级配置项,包括有填充和筛选功能。

isAdvancement

是否开启升级 Select 功能,如果开启需要在 optionConfig 中配置 advancementKeys。

示例代码

完整的示例代码如下:

-- -------------------- ---- -------
------ - ------------- - ---- ------------------------

----- ---------- - --
  ------ ----
  ------ ------
---
  ------ ----
  ------ ------
---
  ------ ----
  ------ ------
---
  ------ ----
  ------ ------
---

----- ------ - -
  -- -----
  ----------- ----------
  -- -----
  ---------------- --
    ------ ----
    ----- --------
  ---
    ------ ----
    ----- --------
  ---
--

-------- --------- -
  ------ -
    --------------
      -----------------------
      -----------------------------------------------
      ---------------------
    --
  --
-

------ ------- --------
展开代码

通过以上示例代码和本文的介绍,相信大家已经了解了 igroot-upgrade-select 的使用方法,它使得升级带有筛选与排序功能的下拉框组件变得很容易,可以让你快速实现你的升级需求,推动你的前端开发效率的提升。

来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/5eedb696b5cbfe1ea0611586

纠错
反馈

纠错反馈