Back to Vant Weapp

NavBar 导航栏

packages/nav-bar/README.md

1.11.72.1 KB
Original Source

NavBar 导航栏

介绍

为页面提供导航功能,常用于页面顶部。

引入

app.jsonindex.json中引入组件,详细介绍见快速上手

json
"usingComponents": {
  "van-nav-bar": "@vant/weapp/nav-bar/index"
}

代码演示

基础用法

html
<van-nav-bar
  title="标题"
  left-text="返回"
  right-text="按钮"
  left-arrow
  bind:click-left="onClickLeft"
  bind:click-right="onClickRight"
/>
js
Page({
  onClickLeft() {
    wx.showToast({ title: '点击返回', icon: 'none' });
  },
  onClickRight() {
    wx.showToast({ title: '点击按钮', icon: 'none' });
  },
});

高级用法

通过 slot 定制内容。

html
<van-nav-bar title="标题" left-text="返回" left-arrow>
  <van-icon name="search" slot="right" />
</van-nav-bar>

API

Props

参数说明类型默认值
title标题string''
left-text左侧文案string''
right-text右侧文案string''
left-arrow是否显示左侧箭头booleanfalse
fixed是否固定在顶部booleanfalse
placeholder固定在顶部时是否开启占位booleanfalse
border是否显示下边框booleantrue
z-index元素 z-indexnumber1
custom-style根节点自定义样式string-
safe-area-inset-top是否留出顶部安全距离(状态栏高度)booleantrue

Slot

名称说明
title自定义标题
left自定义左侧区域内容
right自定义右侧区域内容

Events

事件名说明参数
bind:click-left点击左侧按钮时触发-
bind:click-right点击右侧按钮时触发-

外部样式类

类名说明
custom-class根节点样式类
title-class标题样式类