neverland a0acfd9f7f
[Improvement] optimize build speed (#355)
* fix: Tabbar icon line-height

* [new feature] progress add showPivot prop

* [new feature] TabItem support vue-router

* [new feature] update document header style

* [Doc] add toast english ducoment

* [bugfix] Search box-sizing wrong

* [Doc] update vant-demo respo

* [Doc] translate theme & demo pages

* [Doc] add Internationalization document

* [bugfix] remove unnecessary props

* [fix] optimize clickoutside

* [new feature] optimize find-parent

* [new feature]: change document title accordinng to language

* [new feature] Pagination code review

* [improvement] adjust icon-font unicode

* [improvement] Icon spinner color inherit

* [improvement] icon default width

* [bugfix] DateTimePicker validate date props

* [bugfix] Tab item text ellipsis

* [improvement] optimize single line ellipsis

* [Improvement] optimzie staticClass

* [Improvement] Button: use sfc instread of jsx

* [Improvement] update actionsheet close icon style

* fix: yarn.lock

* fix: icon test cases

* [bugfix] errors during ssr

* [Improvement] SubmitBar add left slot

* [new feature] ImagePreview support manually close

* fix: ImagePreview test case

* [Doc] add switch lang button in mobile

* [bugfix] Popup overlay style update

* [bugfix] NavBar click event

* [Improvement] optimize build speed
2017-11-27 14:58:29 +08:00

2.8 KiB
Raw Blame History

Tabs 标签页

使用指南

import { Tab, Tabs } from 'vant';

Vue.component(Tab.name, Tab);
Vue.component(Tabs.name, Tabs);

代码演示

基础用法

默认情况下启用第一个 tab可以通过active属性激活对应特定索引的 tab

<van-tabs :active="active">
  <van-tab v-for="index in 4" :title="'选项 ' + index">
    内容 {{ index }}
  </van-tab>
</van-tabs>
export default {
  data() {
    return {
      active: 2
    };
  }
}

横向滚动

默认情况下多于4个tab时可以横向滚动tab。可以通过设置swipeThreshold这个阙值多于这个阙值时tab就会支持横向滚动。

<van-tabs>
  <van-tab v-for="index in 8" :title="'选项 ' + index">
    内容 {{ index }}
  </van-tab>
</van-tabs>

禁用标签

在对应的van-tab上设置disabled属性即可。如果需要监听禁用事件,可以在van-tabs上监听disabled事件。

<van-tabs @disabled="onClickDisabled">
  <van-tab v-for="index in 4" :title="'选项 ' + index" :disabled="index === 2">
    内容 {{ index }}
  </van-tab>
</van-tabs>
export default {
  methods: {
    onClickDisabled() {
      Toast('Disabled!')
    }
  }
};

样式风格

Tabs目前有两种样式:linecard,默认为line样式,也就上面基础用法中的样式,你可以在van-tabs上设置typecard改为card样式。

<van-tabs type="card">
  <van-tab v-for="index in 4" :title="'选项 ' + index">
    内容 {{ index }}
  </van-tab>
</van-tabs>

点击事件

可以在van-tabs上绑定一个click事件,事件处理函数有一个参数,参数为对应tabtabs中的索引。

<van-tabs @click="handleTabClick">
  <van-tab v-for="index in 4" :title="'选项 ' + index">
    内容 {{ index }}
  </van-tab>
</van-tabs>
export default {
  methods: {
    handleTabClick(index) {
      Toast(index);
    }
  }
};

Tabs API

参数 说明 类型 默认值 可选
type Tab 样式类型 String line card
active 默认激活的 tab String Number 0 -
duration 切换 tab 的动画时间 Number 0.3 -
swipeThreshold 滚动阀值,设置 Tab 超过多少个可滚动 Number 4 -

Tab API

参数 说明 类型 默认值 可选
title tab的标题 String - -
disabled 是否禁用这个tab Boolean false -

Tabs Event

事件名 说明 参数
click 某个tab点击事件 index点击的tab的索引
disabled 某个tab禁用时点击事件 index点击的tab的索引