VEUI

VEUI on GitHub
Play!中文

Sidenav

Examples

Normal

Combine the Sidenav with Vue Router.

  • Basic
  • Groups
  • Form Controls
Edit this demo on GitHubEdit
<template>
<article>
  <veui-sidenav :items="items"/>
</article>
</template>

<script>
import { Sidenav } from 'veui'

export default {
  name: 'veui-sidenav-demo',
  components: {
    'veui-sidenav': Sidenav
  },
  data () {
    return {
      items: [
        {
          label: 'Basic',
          children: [
            {
              label: 'Button',
              to: '/components/button'
            },
            {
              label: 'Dropdown',
              to: '/components/dropdown'
            }
          ]
        },
        {
          label: 'Groups',
          children: [
            {
              label: 'RadioGroup',
              to: '/components/radio-group'
            },
            {
              label: 'CheckboxGroup',
              to: '/components/checkbox-group'
            }
          ]
        },
        {
          label: 'Form Controls',
          children: [
            {
              label: 'Text Fields',
              children: [
                {
                  label: 'Input',
                  to: '/components/input'
                },
                {
                  label: 'Textarea',
                  to: '/components/textarea'
                }
              ]
            },
            {
              label: 'Pickers',
              children: [
                {
                  label: 'Select',
                  to: '/components/select'
                },
                {
                  label: 'DatePicker',
                  to: '/components/date-picker'
                },
                {
                  label: 'TimePicker',
                  to: '/components/time-picker'
                }
              ]
            }
          ]
        }
      ]
    }
  }
}
</script>

Collapsible

With the collapsible prop of Sidebar, you can control the expansion and contraction of the menu.

/demo/sidenav/collaspible.vue
Edit this demo on GitHubEdit
<template>
<veui-layout>
  <veui-header class="header">
    Header
  </veui-header>
  <veui-layout>
    <veui-sidebar collapsible>
      <veui-sidenav
        :items="items"
        collapsible
      />
    </veui-sidebar>
    <veui-layout>
      <veui-content class="content">
        Content
      </veui-content>
      <veui-footer
        class="footer"
        style="background: #ccc;"
      >
        Footer(背景仅为演示)
      </veui-footer>
    </veui-layout>
  </veui-layout>
</veui-layout>
</template>

<script>
import { Layout, Header, Footer, Sidebar, Content, Sidenav } from 'veui'
import 'veui-theme-dls-icons/calendar'
import 'veui-theme-dls-icons/bullseye'
import 'veui-theme-dls-icons/clock'
import 'veui-theme-dls-icons/eye'

export default {
  name: 'veui-sidenav-demo',
  components: {
    'veui-layout': Layout,
    'veui-header': Header,
    'veui-footer': Footer,
    'veui-sidebar': Sidebar,
    'veui-content': Content,
    'veui-sidenav': Sidenav
  },
  data () {
    let items = [
      {
        label: 'Group One',
        name: 'group-one',
        icon: 'calendar',
        children: [
          {
            label: 'Sub One',
            name: 'sub-one',
            children: [
              {
                label: 'Input',
                to: '/components/input'
              }
            ]
          },
          {
            label: 'Loading',
            name: 'Loading',
            to: '/components/loading',
            children: [
              {
                label: 'Switch',
                to: '/components/switch'
              }
            ]
          }
        ]
      },
      {
        label: 'Button',
        name: 'Button',
        to: '/components/button',
        icon: 'bullseye',
        children: [
          {
            label: 'Disabled',
            name: 'Disabled',
            disabled: true,
            children: [
              {
                label: 'Link',
                name: 'Link',
                to: '/components/link'
              }
            ]
          }
        ]
      },
      {
        label: 'Navigation Three',
        name: 'nav-three',
        icon: 'eye',
        disabled: true
      },
      {
        label: 'Navigation Four',
        name: 'nav-four',
        icon: 'clock',
        children: [
          {
            label: 'Progress',
            to: '/components/progress'
          }
        ]
      }
    ]
    return {
      items
    }
  }
}
</script>

<style lang="less" scoped>
.header,
.footer,
.content {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>

Custom slot

  • Group One
  • Navigation Three
  • Navigation Four
Edit this demo on GitHubEdit
<template>
<article>
  <veui-sidenav
    :items="items"
    collapsible
  >
    <template #icon>
      <veui-icon name="calendar"/>
    </template>
  </veui-sidenav>
</article>
</template>

<script>
import { Sidenav, Icon } from 'veui'
import 'veui-theme-dls-icons/calendar'

export default {
  name: 'veui-sidenav-demo',
  components: {
    'veui-sidenav': Sidenav,
    'veui-icon': Icon
  },
  data () {
    let items = [
      {
        label: 'Group One',
        name: 'group-one',
        children: [
          {
            label: 'Sub One',
            name: 'sub-one',
            children: [
              {
                label: 'Input',
                to: '/components/input'
              }
            ]
          },
          {
            label: 'Loading',
            name: 'Loading',
            to: '/components/loading',
            children: [
              {
                label: 'Switch',
                to: '/switch'
              }
            ]
          }
        ]
      },
      {
        label: 'Button',
        name: 'Button',
        to: '/components/button',
        children: [
          {
            label: 'Disabled',
            name: 'Disabled',
            disabled: true,
            children: [
              {
                label: 'Link',
                name: 'Link',
                to: '/link'
              }
            ]
          }
        ]
      },
      {
        label: 'Navigation Three',
        name: 'nav-three',
        disabled: true
      },
      {
        label: 'Navigation Four',
        name: 'nav-four',
        children: [
          {
            label: 'Progress',
            to: '/components/progress'
          }
        ]
      }
    ]
    return {
      items
    }
  }
}
</script>

API

Props

NameTypeDefaultDescription
uistring-

Preset style.

ValueDescription
sSmall size style.
mMedium size style.
itemsArray<Object>[]

An array of data sources, each node is of type {label, to, name, icon, disabled, children, ...}.

NameTypeDescription
labelstringThe text description of the node.
tostring | ObjectThe navigation destination of the node. Refer to the to property of the Link component.
namestringThe unique identifier of the node. Both name and to must exist.
disabledbooleanWhether the node is disabled.
iconstring|{render: function}The icon used by the top-level node.
childrenArray<Object>The array of child nodes, with the array item type the same as the items array item.
activestring-

The currently active node. If the node has a name property, the value is the name property value. Otherwise, the value is the route path generated by to (route.path).

matchesfunction(Object, string): boolean-

Used to find the active item from items when the route changes.

Default implementation: if the project route path is equal to the current route path (===), the project is considered active.

collapsedbooleanfalse

.sync

The current collapsed state.

expandedArray<string>[]

.sync

Specifies the currently expanded node, which is an array corresponding to the name property or route path in the node data of items.

Slots

NameDescription
beforePre-slot.
item

The rendering slot of each node.

Default content: Renders the icon slot and item-label slot.

NameTypeDescription
labelstringThe name of the icon.
tostring | ObjectThe navigation destination of the node. Refer to the to property of the Link component.
namestringThe unique identifier of the node. Both name and to must exist.
disabledbooleanWhether the node is disabled.
iconstringThe icon used by the top-level node.
childrenArray<Object>The array of child nodes, with the array item type the same as the items array item.
icon

The icon slot in front of the node.

Default content: Renders the icon specified by item.icon.

NameTypeDescription
iconstring|{render: function}The name of the icon.
item-label

The text label slot of the node.

Default content: Renders the Link corresponding to the node.

Refer to the item slot parameters.

afterPost-slot.

Events

NameDescription
activateTriggered when the user clicks on a node with to, and the parameter is the entire item data of the active node.
clickTriggered when the user clicks on a node, and the parameter is the entire item data of the active node.
Edit this page on GitHubEdit
© Baidu, Inc. 2024