Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vant Sidebar side navigation


May 07, 2021 Vant


Table of contents


Introduced

import Vue from 'vue';
import { Sidebar, SidebarItem } from 'vant';

Vue.use(Sidebar);
Vue.use(SidebarItem);

Code demo

Basic usage

The index of the currently selected item is bound by v-model

<van-sidebar v-model="activeKey">
  <van-sidebar-item title="标签名称" />
  <van-sidebar-item title="标签名称" />
  <van-sidebar-item title="标签名称" />
</van-sidebar>
export default {
  data() {
    return {
      activeKey: 0
    };
  }
};

Tips

When you set the dot property, a small red dot is displayed in the upper right corner. When you set the info property, the logo appears in the upper right corner

<van-sidebar v-model="activeKey">
  <van-sidebar-item title="标签名称" dot />
  <van-sidebar-item title="标签名称" info="5" />
  <van-sidebar-item title="标签名称" info="99+" />
</van-sidebar>

Disable the option

Disable the option with the disabled property

<van-sidebar v-model="activeKey">
  <van-sidebar-item title="标签名称" />
  <van-sidebar-item title="标签名称" disabled />
  <van-sidebar-item title="标签名称" />
</van-sidebar>

Listen for switching events

Set the change method to listen for events when switching navigation items

<van-sidebar v-model="activeKey" @change="onChange">
  <van-sidebar-item title="标签名1" />
  <van-sidebar-item title="标签名2" />
  <van-sidebar-item title="标签名3" />
</van-sidebar>
import { Notify } from 'vant';

export default {
  data() {
    return {
      activeKey: 0
    };
  },
  methods: {
    onChange(index) {
      Notify({ type: 'primary', message: index });
    }
  }
}

Api

Sidebar Props

Parameters Description Type The default
v-model v2.0.4 The index of the current navigation item number | string 0

Sidebar Events

The name of the event Description Callback parameters
change Triggered when switching navigation items index: The index of the current navigation item

SidebarItem Props

Parameters Description Type The default
title Content string ''
dot v2.2.1 Whether to display a small red dot in the upper right corner boolean false
info The contents of the logo in the upper right corner number | string -
disabled v2.2.0 Whether to disable the item boolean false
Url Click on the link address that jumps string -
to v2.0.4 Click to jump the target routing object, with the to property of vue-router string | object -
replace v2.0.4 Whether to replace the current page history when jumping boolean false

SidebarItem Events

The name of the event Description Callback parameters
Click Triggered when clicked index: The index of the current navigation item


Example demonstration