codecamp

Vant Weapp NavBar 导航栏

介绍

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

引入

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

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

代码演示

基础用法

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

高级用法

通过 slot 定制内容。

<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 是否显示左侧箭头 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 标题样式类


实例演示

Vant Weapp IndexBar 索引栏
Vant Weapp Sidebar 侧边导航
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Vant Weapp 废弃

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }