注册 X
提交 注:点击提交后系统会发送邮件到邮箱验证!(仅支持中国大陆邮箱)
我已阅读并同意 服务条款
首页 > IT技术笔记 > 查看笔记

vant-Tabbar 标签栏

引入

        
        
      

代码演示

基础用法

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

        
        
      

        
        
      

通过名称匹配

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

        
        
      

        
        
      

徽标提示

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

        
        
      

自定义图标

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

        
        
      

        
        
      

自定义颜色

        
        
      

监听切换事件

        
        
      

        
        
      

路由模式

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

        
        
      

API

Tabbar Props

参数说明类型默认值
v-model当前选中标签的名称或索引值number / string0
fixed是否固定在底部booleantrue
border是否显示外边框booleantrue
z-index元素 z-indexnumber / string1
active-color选中标签的颜色string#1989fa
inactive-color未选中标签的颜色string#7d7e80
route是否开启路由模式booleanfalse
placeholder v2.6.0固定在底部时,是否在标签位置生成一个等高的占位元素booleanfalse
safe-area-inset-bottom是否开启[底部安全区适配](https://youzan.github.io/vant/v2/#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei),设置 fixed 时默认开启booleanfalse
before-change v2.10.4切换标签前的回调函数,返回 false 可阻止切换,支持返回 Promise(name) => boolean / Promise-

Tabbar Events

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

TabbarItem Props

参数说明类型默认值
name标签名称,作为匹配的标识符number / string当前标签的索引值
icon[图标名称](https://youzan.github.io/vant/v2/#/zh-CN/icon)或图片链接string-
icon-prefix v2.5.3图标类名前缀,同 Icon 组件的 [class-prefix 属性](https://youzan.github.io/vant/v2/#/zh-CN/icon#props)stringvan-icon
dot是否显示图标右上角小红点booleanfalse
badge v2.5.6图标右上角徽标的内容number / string-
info图标右上角徽标的内容(已废弃,请使用 badge 属性)number / string-
url点击后跳转的链接地址string-
to点击后跳转的目标路由对象,同 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to)string / object-
replace是否在跳转时替换当前页面历史booleanfalse

TabbarItem Slots

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

样式变量

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

主题定制

名称默认值描述
@tabbar-height50px-
@tabbar-z-index1-
@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-height1-
@tabbar-item-icon-size22px-
@tabbar-item-margin-bottom4px-


效果图:


 打赏        分享



评论

邮箱: 昵称: