# NavBar 导航栏

### 引入

在`index.config.js中引入组件
```json
"usingComponents": {
  "van-nav-bar": "@vant/weapp/nav-bar/index"
}
```

## 代码演示

### 基础用法

```html
<van-nav-bar
  title="标题"
  leftText="返回"
  rightText="按钮"
  leftArrow
  onLeft={() => this.onClickLeft()}
  onRight={() => this.onClickRight()}
/>
```

```js

  onClickLeft() {
    wx.showToast({ title: '点击返回', icon: 'none' });
  }
  onClickRight() {
    wx.showToast({ title: '点击按钮', icon: 'none' });
  }

```

### 高级用法

通过 slot 定制内容

```html
<van-nav-bar title="标题" leftText="返回" leftArrow onLeft={() => this.onClickLeft()}>
    <van-icon name="search" slot="right" customClass="icon" onClick={() => this.onClickRight()}/>
</van-nav-bar>
```

## API
### 注:属性应用在组件上需要统一使用驼峰式命名，如custom-class应变为
```html
<van-button type="primary" customClass='myClass' size="large">大号按钮</van-button>
```
### 注:事件应用在组件上需要统一使用驼峰式命名，如bind:click/bind:search/bind:before-enter应变为
```html
<van-button type="primary" onClick={()=>this.onClick()}>大号按钮</van-button>
<van-search type="primary" onSearch={()=>this.onSearch()}>大号按钮</van-search>
<van-transition type="primary" onBeforeEnter={()=>this.onBeforeEnter()}>大号按钮</van-transition>
```
### Props

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

### Slot

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

### Events

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

### 外部样式类

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