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/tabbar

v1.0.1

Published

### 引入

Downloads

1

Readme

Tabbar 标签栏

引入

// 方式1(推荐)
import Vue from 'vue';
import Tabbar from '@ophiuchus/tabbar';

Vue.use(Tabbar);
// 方式2
import Vue from 'vue';
import { Tabbar, TabbarItem } from '@ophiuchus/tabbar';

Vue.component(Tabbar.name, Tabbar);
Vue.component(TabbarItem.name, TabbarItem);

代码演示

基础用法

v-model 默认绑定选中标签的索引值,通过修改 v-model 即可切换选中的标签。

<sf-tabbar v-model="active">
  <sf-tabbar-item icon="location-o">标签</sf-tabbar-item>
  <sf-tabbar-item icon="search">标签</sf-tabbar-item>
  <sf-tabbar-item icon="question-o">标签</sf-tabbar-item>
  <sf-tabbar-item icon="volume-o">标签</sf-tabbar-item>
</sf-tabbar>
export default {
  data() {
    return {
      active: 0,
    };
  },
};

通过名称匹配

在标签指定 name 属性的情况下,v-model 的值为当前标签的 name

<sf-tabbar v-model="active">
  <sf-tabbar-item name="location" icon="location-o">标签</sf-tabbar-item>
  <sf-tabbar-item name="search" icon="search">标签</sf-tabbar-item>
  <sf-tabbar-item name="question" icon="question-o">标签</sf-tabbar-item>
  <sf-tabbar-item name="question" icon="question-o">标签</sf-tabbar-item>
</sf-tabbar>
export default {
  data() {
    return {
      active: 'location',
    };
  },
};

徽标提示

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

<sf-tabbar v-model="active">
  <sf-tabbar-item icon="location-o">标签</sf-tabbar-item>
  <sf-tabbar-item icon="search" dot>标签</sf-tabbar-item>
  <sf-tabbar-item icon="question-o" badge="5">标签</sf-tabbar-item>
  <sf-tabbar-item icon="volume-o" badge="20">标签</sf-tabbar-item>
</sf-tabbar>

自定义图标

通过 icon 插槽自定义图标,可以通过 slot-scope 判断标签是否选中。

<sf-tabbar v-model="active">
  <sf-tabbar-item badge="3">
    <span>自定义</span>
    <template #icon="props">
      <img :src="props.active ? icon.active : icon.inactive" />
    </template>
  </sf-tabbar-item>
  <sf-tabbar-item icon="search">标签</sf-tabbar-item>
  <sf-tabbar-item icon="volume-o">标签</sf-tabbar-item>
</sf-tabbar>
export default {
  data() {
    return {
      active: 0,
      icon: {
        active: 'https://img3.tuhu.org/3rq0A7JtvChtaD5QMO3HgA_w98_h78.png',
        inactive: 'https://img3.tuhu.org/4rjx6O9PLzcq84oLWQeXww_w98_h78.png',
      },
    };
  },
};

自定义颜色

<sf-tabbar v-model="active" active-color="#ee0a24" inactive-color="#000">
  <sf-tabbar-item icon="location-o">标签</sf-tabbar-item>
  <sf-tabbar-item icon="search">标签</sf-tabbar-item>
  <sf-tabbar-item icon="question-o">标签</sf-tabbar-item>
  <sf-tabbar-item icon="volume-o">标签</sf-tabbar-item>
</sf-tabbar>

监听切换事件

<sf-tabbar v-model="active" @change="onChange">
  <sf-tabbar-item icon="location-o">标签1</sf-tabbar-item>
  <sf-tabbar-item icon="search">标签2</sf-tabbar-item>
  <sf-tabbar-item icon="question-o">标签3</sf-tabbar-item>
  <sf-tabbar-item icon="volume-o">标签4</sf-tabbar-item>
</sf-tabbar>
import Notify from '@ophiuchus/notify';

export default {
  methods: {
    onChange(index) {
      Notify({ type: 'primary', message: index });
    },
  },
};

路由模式

标签栏支持路由模式,用于搭配 vue-router 使用。路由模式下会匹配页面路径和标签的 to 属性,并自动选中对应的标签。

<router-view />

<sf-tabbar route>
  <sf-tabbar-item replace to="/location" icon="location-o">标签</sf-tabbar-item>
  <sf-tabbar-item replace to="/search" icon="search">标签</sf-tabbar-item>
</sf-tabbar>

API

Tabbar Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | v-model | 当前选中标签的名称或索引值 | number | string | 0 | | fixed | 是否固定在底部 | boolean | true | | border | 是否显示外边框 | boolean | true | | z-index | 元素 z-index | number | string | 1 | | active-color | 选中标签的颜色 | string | #1989fa | | inactive-color | 未选中标签的颜色 | string | #7d7e80 | | route | 是否开启路由模式 | boolean | false | | placeholder | 固定在底部时,是否在标签位置生成一个等高的占位元素 | boolean | false | | safe-area-inset-bottom | 是否开启底部安全区适配,设置 fixed 时默认开启 | boolean | false | | before-change | 切换标签前的回调函数,返回 false 可阻止切换,支持返回 Promise | (name) => boolean | Promise | - |

Tabbar Events

| 事件名 | 说明 | 回调参数 | | ------ | -------------- | ---------------------------------- | | change | 切换标签时触发 | active: 当前选中标签的名称或索引值 |

TabbarItem Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | name | 标签名称,作为匹配的标识符 | number | string | 当前标签的索引值 | | icon | 图标名称或图片链接 | string | - | | icon-prefix | 图标类名前缀,同 Icon 组件的 class-prefix 属性 | string | sf-icon | | dot | 是否显示图标右上角小红点 | boolean | false | | badge | 图标右上角徽标的内容 | number | string | - | | info | 图标右上角徽标的内容(已废弃,请使用 badge 属性) | number | string | - | | url | 点击后跳转的链接地址 | string | - | | to | 点击后跳转的目标路由对象,同 vue-router 的 to 属性 | string | object | - | | replace | 是否在跳转时替换当前页面历史 | boolean | false |

TabbarItem Slots

| 名称 | 说明 | 参数 | | ---- | ---------- | ---------------------- | | icon | 自定义图标 | active: 是否为选中标签 |

样式变量

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

| 名称 | 默认值 | 描述 | | ------------------------------------ | -------------------------- | ---- | | @tabbar-height | 50px | - | | @tabbar-z-index | 1 | - | | @tabbar-background-color | @white | - | | @tabbar-item-font-size | @font-size-sm | - | | @tabbar-item-text-color | @gray-7 | - | | @tabbar-item-active-color | @blue | - | | @tabbar-item-active-background-color | @tabbar-background-color | - | | @tabbar-item-line-height | 1 | - | | @tabbar-item-icon-size | 22px | - | | @tabbar-item-margin-bottom | 4px | - |