VEUI

VEUI on GitHub
Play!中文

Drawer

Examples

Placement

Use the placement prop to control the position where the drawer pops up.

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-checkbox
      v-model="modal"
      class="item"
    >
      Modal
    </veui-checkbox>
    <veui-checkbox
      v-model="outsideClosable"
      class="item"
    >
      Outside Closable
    </veui-checkbox>
  </section>

  <section>
    <veui-button
      class="item"
      @click="topOpen = true"
    >
      Top
    </veui-button>
    <veui-button
      class="item"
      @click="rightOpen = true"
    >
      Right
    </veui-button>
    <veui-button
      class="item"
      @click="bottomOpen = true"
    >
      Bottom
    </veui-button>
    <veui-button
      class="item"
      @click="leftOpen = true"
    >
      Left
    </veui-button>
  </section>

  <veui-drawer
    :open.sync="topOpen"
    :outside-closable="outsideClosable"
    :modal="modal"
    placement="top"
  >
    <p>content area</p>
    <template #title="{ close }">
      <a @click="close">
        关闭
      </a>
    </template>
    <template #foot>
      <div>Foot</div>
    </template>
  </veui-drawer>
  <veui-drawer
    :open.sync="rightOpen"
    :modal="modal"
    :outside-closable="outsideClosable"
    placement="right"
    title="Title"
  />
  <veui-drawer
    title="Title"
    :modal="modal"
    :open.sync="bottomOpen"
    :outside-closable="outsideClosable"
    placement="bottom"
  />
  <veui-drawer
    title="Title"
    :modal="modal"
    :open.sync="leftOpen"
    :outside-closable="outsideClosable"
    placement="left"
  />
</article>
</template>

<script>
import { Checkbox, Drawer, Button } from 'veui'

export default {
  name: 'drawer-demo',
  components: {
    'veui-drawer': Drawer,
    'veui-checkbox': Checkbox,
    'veui-button': Button
  },
  data () {
    return {
      modal: true,
      outsideClosable: false,
      topOpen: false,
      rightOpen: false,
      bottomOpen: false,
      leftOpen: false
    }
  }
}
</script>

<style lang="less" scoped>
section {
  & + & {
    margin-top: 20px;
  }
}

.item {
  & + & {
    margin-left: 20px;
  }
}
</style>

Use the modal prop to control whether the drawer is modal or not.

Edit this demo on GitHubEdit
<template>
<article>
  <veui-button
    class="button"
    @click="modalOpen = true"
  >
    Modal
  </veui-button>
  <veui-button
    class="button"
    @click="nonModalOpen = true"
  >
    Non-modal
  </veui-button>
  <veui-drawer
    title="System"
    :open.sync="modalOpen"
    @ok="handleModalClose(true)"
    @cancel="handleModalClose"
  >
    Do you want to refresh the page?
  </veui-drawer>
  <veui-drawer
    title="System"
    :open.sync="nonModalOpen"
    :modal="false"
    @ok="handleModalClose(true)"
    @cancel="handleModalClose"
  >
    Do you want to refresh the page?
  </veui-drawer>
</article>
</template>

<script>
import { Drawer, Button } from 'veui'

export default {
  components: {
    'veui-drawer': Drawer,
    'veui-button': Button
  },
  data () {
    return {
      modalOpen: false,
      nonModalOpen: false
    }
  },
  methods: {
    handleModalClose (ok) {
      this.modalOpen = false
      if (ok) {
        location.reload()
      }
    },
    handleNonModalClose (ok) {
      this.nonModalOpen = false
      if (ok) {
        location.reload()
      }
    }
  }
}
</script>

<style lang="less" scoped>
.button {
  margin-right: 20px;
}
</style>

Custom content

Edit this demo on GitHubEdit
<template>
<article>
  <veui-button
    class="button"
    @click="simpleOpen = true"
  >
    Title & content
  </veui-button>
  <veui-drawer
    :open.sync="simpleOpen"
    title="Customized Title & Content"
    @ok="simpleOpen = false"
    @cancel="simpleOpen = false"
  >
    Customized content via <code>&lt;slot&gt;</code>.
  </veui-drawer>

  <veui-button
    class="button"
    @click="titleIconOpen = true"
  >
    Icon in Title
  </veui-button>
  <veui-drawer
    :open.sync="titleIconOpen"
    @ok="titleIconOpen = false"
    @cancel="titleIconOpen = false"
  >
    <template #title>
      Title with Icon <veui-icon name="flag"/>
    </template>
    Customized content via <code>&lt;slot&gt;</code>.
  </veui-drawer>

  <veui-button
    class="button"
    @click="footOpen = true"
  >
    Foot
  </veui-button>
  <veui-drawer
    :open.sync="footOpen"
    title="Customized Foot"
  >
    Customized content via <code>&lt;slot&gt;</code>.
    <template #foot="{ close }">
      <veui-button
        ui="s primary"
        @click="close('ok')"
      >
        Close
      </veui-button>
    </template>
  </veui-drawer>
</article>
</template>

<script>
import { Drawer, Button, Icon } from 'veui'
import 'veui-theme-dls-icons/flag'

export default {
  components: {
    'veui-drawer': Drawer,
    'veui-button': Button,
    'veui-icon': Icon
  },
  data () {
    return {
      simpleOpen: false,
      titleIconOpen: false,
      footOpen: false
    }
  }
}
</script>

<style lang="less" scoped>
.button {
  margin-right: 20px;
}
</style>

API

Props

NameTypeDefaultDescription
uistring-

Predefined styles.

ValueDescription
sSmall content size (size of content and components, not the overall size of the drawer).
mMedium content size (size of content and components, not the overall size of the drawer).
placementstring'right'

Drawer position.

ValueDescription
topSlide out from the top.
rightSlide out from the right.
bottomSlide out from the bottom.
leftSlide out from the left.
modalbooleantrueWhether the drawer is modal. If it's modal, it will cover the underlying content and grab the focus (the focus will return after it's closed).
titlestring-The text of the drawer title. If both the title prop and the title slot are specified, the latter will be used.
openbooleanfalse

.sync

Whether to show the drawer or not.

closablebooleantrueWhether to show the close button.
outside-closablebooleanfalseWhether to close the drawer when clicked outside the drawer.
escapablebooleanfalseWhether the drawer can be closed by pressing the esc key. Only effective when closable is true.
prioritynumber-The z-index of the drawer layer. Refer to the Overlay component's priority prop.
footlessbooleanfalseWhether to hide the default footer.
loadingbooleanfalseWhether it's in the loading state. When it's in the loading state, the OK button will also enter the loading state and cannot be clicked.
disabledbooleanfalseWhether it's in the disabled state. When it's in the disabled state, the OK button will also enter the disabled state and cannot be clicked.
ok-labelstring-The text content of the "OK" button.
cancel-labelstring-The text content of the "Cancel" button.
before-closefunction(string): boolean=|Promise<boolean>-Run after the operation that triggers the closing. Refer to the Dialog component's before-close prop.
overlay-classstring | Object-The class name of the drawer layer root element. Refer to the Overlay component's overlay-class prop.

Slots

NameDescription
defaultContent area.
titleTitle area. If both the title prop and the title slot are specified, the latter will be used.
foot

Footer area. The "OK" and "Cancel" buttons will be displayed by default.

NameTypeDescription
closefunction(type: string): voidA callback function that triggers the drawer to close. type is the type of the closing action, which will be passed as a parameter to the before-close hook function and will also trigger an event with the same name.

Events

NameDescription
okFired when the "OK" button is clicked or when the close('ok') function is called in the scope.
cancelFired when the "Cancel" button is clicked, the close button is clicked, or the drawer is closed by pressing esc or calling the close('cancel') function in the scope.
<value>Fired when the close(value) function is called in the scope.
afteropenFired after the drawer is opened. The drawer content will be rendered after it's opened, so if there are logic that depends on the content rendering, please execute them after this event is triggered.
aftercloseFired after the drawer is closed. If the style theme provides an exit animation, it will be triggered after the exit animation is completed.
Edit this page on GitHubEdit
© Baidu, Inc. 2024