npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ophiuchus/tree-select

v1.0.1

Published

### 引入

Downloads

1

Readme

TreeSelect 分类选择

引入

import Vue from 'vue';
import { TreeSelect } from 'vant';

Vue.use(TreeSelect);

代码演示

单选模式

item 为分类显示所需的数据,数据格式见下方示例。main-active-index 表示左侧高亮选项的索引,active-id 表示右侧高亮选项的 id。

<sf-tree-select
  :items="items"
  :active-id.sync="activeId"
  :main-active-index.sync="activeIndex"
/>
export default {
  data() {
    return {
      items,
      activeId: 1,
      activeIndex: 0,
    };
  },
};

多选模式

active-id 为数组格式时,可以选中多个右侧选项。

<sf-tree-select
  :items="items"
  :active-id.sync="activeIds"
  :main-active-index.sync="activeIndex"
/>
export default {
  data() {
    return {
      items,
      activeIds: [1, 2],
      activeIndex: 0,
    };
  },
};

自定义内容

通过 content 插槽可以自定义右侧区域的内容。

<sf-tree-select height="55vw" :items="items" :main-active-index.sync="active">
  <template #content>
    <sf-image
      v-if="active === 0"
      src="https://img01.yzcdn.cn/vant/apple-1.jpg"
    />
    <sf-image
      v-if="active === 1"
      src="https://img01.yzcdn.cn/vant/apple-2.jpg"
    />
  </template>
</sf-tree-select>
export default {
  data() {
    return {
      active: 0,
      items: [{ text: '分组 1' }, { text: '分组 2' }],
    };
  },
};

徽标提示

设置 dot 属性后,会在图标右上角展示一个小红点;设置 badge 属性后,会在图标右上角展示相应的徽标。

<sf-tree-select
  height="55vw"
  :items="items"
  :main-active-index.sync="activeIndex"
/>
export default {
  data() {
    return {
      activeIndex: 0,
      items: [
        { text: '浙江', children: [], dot: true },
        { text: '江苏', children: [], badge: 5 },
      ],
    };
  },
};

API

Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | items | 分类显示所需的数据 | Item[] | [] | | height | 高度,默认单位为px | number | string | 300 | | main-active-index | 左侧选中项的索引 | number | string | 0 | | active-id | 右侧选中项的 id,支持传入数组 | number | string |(number | string)[] | 0 | | max | 右侧项最大选中个数 | number | string | Infinity | | selected-icon | 自定义右侧栏选中状态的图标 | string | success |

Events

| 事件名 | 说明 | 回调参数 | | ---------- | -------------------- | ------------------------- | | click-nav | 点击左侧导航时触发 | index:被点击的导航的索引 | | click-item | 点击右侧选择项时触发 | data: 该点击项的数据 |

Slots

| 名称 | 说明 | | ------- | ------------------ | | content | 自定义右侧区域内容 |

Item 数据结构

items 整体为一个数组,数组内包含一系列描述分类的对象,每个分类里,text表示当前分类的名称,children表示分类里的可选项。

[
  {
    // 导航名称
    text: '所有城市',
    // 导航名称右上角徽标
    badge: 3,
    // 是否在导航名称右上角显示小红点
    dot: true,
    // 导航节点额外类名
    className: 'my-class',
    // 该导航下所有的可选项
    children: [
      {
        // 名称
        text: '温州',
        // id,作为匹配选中状态的标识符
        id: 1,
        // 禁用选项
        disabled: true,
      },
      {
        text: '杭州',
        id: 2,
      },
    ],
  },
];

样式变量

组件提供了下列 Less 变量,可用于自定义样式,使用方法请参考主题定制

| 名称 | 默认值 | 描述 | | ------------------------------------- | ------------------- | ---- | | @tree-select-font-size | @font-size-md | - | | @tree-select-nav-background-color | @background-color | - | | @tree-select-content-background-color | @white | - | | @tree-select-nav-item-padding | 14px @padding-sm | - | | @tree-select-item-height | 48px | - | | @tree-select-item-active-color | @red | - | | @tree-select-item-disabled-color | @gray-5 | - | | @tree-select-item-selected-size | 16px | - |