Skip to content

Drawer

A simple drawer used for display or quick opening. It can be used to show information or dynamically create and insert content.

Basic Usage

The simplest usage: show/hide the dialog by controlling the property value.

<template>
  <div>
    <b-button type="primary" @click="value = true">open</b-button>
    <b-drawer v-model="value" title="Drawer Title">
      <p>Drawer content goes here</p>
    </b-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const value = ref(false)
</script>

Open from Left

Set placement="left" to open from the left side

<template>
  <div>
    <b-button type="primary" @click="value = true">Open from Left</b-button>
    <b-drawer v-model="value" title="drawerTitle" placement="left" width="500px">
      <p>I am the left-side drawer</p>
    </b-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const value = ref(false)
</script>

inner Mode

Can set inner mode to open within a specific container

<template>
  <div
    style="position: relative; height: 400px; background: #eee; border: 1px solid #eee; z-index: 2"
  >
    <b-button type="primary" @click="valueInner = true">Inner Drawer</b-button>
    <b-drawer v-model="valueInner" title="Inner Drawer" :lock-scroll="false" inner :z-index="10">
      <p>I am the inner drawer</p>
    </b-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const valueInner = ref(false)
</script>

Info Preview Box

<template>
  <div>
    <b-button type="primary" @click="value = true">Info Preview</b-button>
    <b-drawer v-model="value" :show-close="false" width="640">
      <p :style="pStyle">User Info</p>
      <p :style="pStyle">Personal Info</p>
      <div class="demo-drawer-profile">
        <p flex="box:mean" class="mb-10">
          <span>Name: wangbin</span>
          <span>Phone: +86 1762516xxxx</span>
        </p>
        <p flex="box:mean" class="mb-10">
          <span>City: XuzhouCity</span>
          <span>District: Gulou District</span>
        </p>
        <p flex="box:mean" class="mb-10">
          <span>Date of Birth: 1990-04</span>
          <span>Occupation: Web Frontend</span>
        </p>
      </div>
      <b-divider></b-divider>
      <p :style="pStyle">Company</p>
      <div class="demo-drawer-profile">
        <p flex="box:mean" class="mb-10">
          <span>Name: xxxx Co., Ltd.</span>
          <span>Phone: +86 1762516xxxx</span>
        </p>
        <p flex="box:mean" class="mb-10">
          <span>Address: No.88, xx Street, xx District, Xuzhou City</span>
          <span>Phone: +86 1762516xxxx</span>
        </p>
      </div>
      <b-divider></b-divider>
      <p :style="pStyle">Contact Us</p>
      <div class="demo-drawer-profile">
        <p flex="box:mean" class="mb-10">
          <span>Email: 316281400@qq.com</span>
          <span>Phone: +86 1762516xxxx</span>
        </p>
        <p class="mb-10">
          github:
          <a href="https://github.com/wangbin3162/bin-ui-design" target="_blank">
            https://github.com/wangbin3162/bin-ui-design-design
          </a>
        </p>
      </div>
    </b-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const value = ref(false)

const pStyle = {
  fontSize: '16px',
  color: 'rgba(0,0,0,0.85)',
  lineHeight: '24px',
  marginBottom: '16px'
}
</script>

Nestingdrawer

Drawers can be nested within each other, but this is generally not recommended to avoid too many z-index levels affecting user interaction.

<template>
  <div>
    <b-button type="primary" @click="value = true">Opendrawer</b-button>
    <b-drawer v-model="value" title="First Level Drawer" width="512" :show-close="false">
      <b-button type="primary" @click="value1 = true">Open Second Level Drawer</b-button>
    </b-drawer>
    <b-drawer v-model="value1" title="Second Level Drawer" :show-close="false">This is the second level drawer</b-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const value = ref(false)
const value1 = ref(false)
</script>

DraggableWidth

Can set dragdrawer

<template>
  <div>
    <b-button type="primary" @click="value = true">open</b-button>
    <b-drawer v-model="value" title="drawerTitle" draggable>
      <p>I am the drawer content</p>
    </b-drawer>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const value = ref(false)
</script>

Props

ParameterDescriptionTypeOptionsDefault
modelValueWhether to show; use v-model for two-way bindingBooleanfalse
titleTitle. If a custom header slot is used, the title prop is ignored.String
placementDirectionStringleft/rightright
append-to-bodyWhether to append the dialog to the bodyBooleanfalse
widthDrawer widthNumber300
min-widthDrawer minimum widthNumber300
show-closeWhether to show close buttonBooleantrue
mask-closableAllow clicking the mask to closeBooleantrue
maskWhether to show maskBooleantrue
stylesDrawer middle layer stylesObject
innerWhether to set the drawer to open within a specific element. When enabling this property, disable append-to-body propertyBooleanfalse
draggableEnable drag to adjust widthBooleanfalse
before-closeEvent before closing; return a Promise to prevent closingFunction
lock-scrollWhether to lock scrollingBooleantrue

Events

Event NameDescriptionReturn Value
closeTriggers when drawer closes
resize-widthAdjust width

Slot

NameDescription
headerCustom header
closeClose button
defaultDrawer body content