Drawer 抽屉

屏幕边缘滑出的浮层面板。

何时使用

抽屉从父窗体边缘滑入,覆盖住部分父窗体内容。用户在抽屉内操作时不必离开当前任务,操作完成后,可以平滑地回到到原任务。

  • 当需要一个附加的面板来控制父窗体内容,这个面板在需要时呼出。比如,控制界面展示样式,往界面中添加内容。
  • 当需要在当前任务流中插入临时任务,创建或预览附加内容。比如展示协议条款,创建子对象。

代码演示

Drawer抽屉 - 图1

基础抽屉

基础抽屉,点击触发按钮抽屉从右滑出,点击遮罩区关闭

  1. <template>
  2. <div>
  3. <a-button type="primary" @click="showDrawer">
  4. Open
  5. </a-button>
  6. <a-drawer
  7. title="Basic Drawer"
  8. placement="right"
  9. :closable="false"
  10. @close="onClose"
  11. :visible="visible"
  12. >
  13. <p>Some contents...</p>
  14. <p>Some contents...</p>
  15. <p>Some contents...</p>
  16. </a-drawer>
  17. </div>
  18. </template>
  19. <script>
  20. export default {
  21. data() {
  22. return {
  23. visible: false,
  24. }
  25. },
  26. methods: {
  27. showDrawer() {
  28. this.visible = true
  29. },
  30. onClose() {
  31. this.visible = false
  32. },
  33. },
  34. }
  35. </script>

Drawer抽屉 - 图2

自定义位置

自定义位置,点击触发按钮抽屉从相应的位置滑出,点击遮罩区关闭

  1. <template>
  2. <div>
  3. <a-radio-group
  4. style="margin-right: 8px"
  5. :defaultValue="placement"
  6. @change="onChange"
  7. >
  8. <a-radio value="top">top</a-radio>
  9. <a-radio value="right">right</a-radio>
  10. <a-radio value="bottom">bottom</a-radio>
  11. <a-radio value="left">left</a-radio>
  12. </a-radio-group>
  13. <a-button type="primary" @click="showDrawer">
  14. Open
  15. </a-button>
  16. <a-drawer
  17. title="Basic Drawer"
  18. :placement="placement"
  19. :closable="false"
  20. @close="onClose"
  21. :visible="visible"
  22. >
  23. <p>Some contents...</p>
  24. <p>Some contents...</p>
  25. <p>Some contents...</p>
  26. </a-drawer>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. visible: false,
  34. placement: 'left'
  35. }
  36. },
  37. methods: {
  38. showDrawer() {
  39. this.visible = true
  40. },
  41. onClose() {
  42. this.visible = false
  43. },
  44. onChange(e) {
  45. this.placement = e.target.value
  46. }
  47. },
  48. }
  49. </script>

Drawer抽屉 - 图3

抽屉表单

在抽屉中使用表单。

  1. <template>
  2. <div>
  3. <a-button type="primary" @click="showDrawer">
  4. <a-icon type="plus" /> New account
  5. </a-button>
  6. <a-drawer
  7. title="Create a new account"
  8. :width="720"
  9. @close="onClose"
  10. :visible="visible"
  11. :wrapStyle="{height: 'calc(100% - 108px)',overflow: 'auto',paddingBottom: '108px'}"
  12. >
  13. <a-form :form="form" layout="vertical" hideRequiredMark>
  14. <a-row :gutter="16">
  15. <a-col :span="12">
  16. <a-form-item label="Name">
  17. <a-input
  18. v-decorator="['name', {
  19. rules: [{ required: true, message: 'Please enter user name' }]
  20. }]"
  21. placeholder="Please enter user name"
  22. />
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="12">
  26. <a-form-item label="Url">
  27. <a-input
  28. v-decorator="['url', {
  29. rules: [{ required: true, message: 'please enter url' }]
  30. }]"
  31. style="width: 100%"
  32. addonBefore="http://"
  33. addonAfter=".com"
  34. placeholder="please enter url"
  35. />
  36. </a-form-item>
  37. </a-col>
  38. </a-row>
  39. <a-row :gutter="16">
  40. <a-col :span="12">
  41. <a-form-item label="Owner">
  42. <a-select
  43. v-decorator="['owner', {
  44. rules: [{ required: true, message: 'Please select an owner' }]
  45. }]"
  46. placeholder="Please a-s an owner"
  47. >
  48. <a-select-option value="xiao">Xiaoxiao Fu</a-select-option>
  49. <a-select-option value="mao">Maomao Zhou</a-select-option>
  50. </a-select>
  51. </a-form-item>
  52. </a-col>
  53. <a-col :span="12">
  54. <a-form-item label="Type">
  55. <a-select
  56. v-decorator="['type', {
  57. rules: [{ required: true, message: 'Please choose the type' }]
  58. }]"
  59. placeholder="Please choose the type"
  60. >
  61. <a-select-option value="private">Private</a-select-option>
  62. <a-select-option value="public">Public</a-select-option>
  63. </a-select>
  64. </a-form-item>
  65. </a-col>
  66. </a-row>
  67. <a-row :gutter="16">
  68. <a-col :span="12">
  69. <a-form-item label="Approver">
  70. <a-select
  71. v-decorator="['approver', {
  72. rules: [{ required: true, message: 'Please choose the approver' }]
  73. }]"
  74. placeholder="Please choose the approver"
  75. >
  76. <a-select-option value="jack">Jack Ma</a-select-option>
  77. <a-select-option value="tom">Tom Liu</a-select-option>
  78. </a-select>
  79. </a-form-item>
  80. </a-col>
  81. <a-col :span="12">
  82. <a-form-item label="DateTime">
  83. <a-date-picker
  84. v-decorator="['dateTime', {
  85. rules: [{ required: true, message: 'Please choose the dateTime' }]
  86. }]"
  87. style="width: 100%"
  88. :getPopupContainer="trigger => trigger.parentNode"
  89. />
  90. </a-form-item>
  91. </a-col>
  92. </a-row>
  93. <a-row :gutter="16">
  94. <a-col :span="24">
  95. <a-form-item label="Description">
  96. <a-textarea
  97. v-decorator="['description', {
  98. rules: [{ required: true, message: 'Please enter url description' }]
  99. }]"
  100. :rows="4"
  101. placeholder="please enter url description"
  102. />
  103. </a-form-item>
  104. </a-col>
  105. </a-row>
  106. </a-form>
  107. <div
  108. :style="{
  109. position: 'absolute',
  110. left: 0,
  111. bottom: 0,
  112. width: '100%',
  113. borderTop: '1px solid #e9e9e9',
  114. padding: '10px 16px',
  115. background: '#fff',
  116. textAlign: 'right',
  117. }"
  118. >
  119. <a-button
  120. :style="{marginRight: '8px'}"
  121. @click="onClose"
  122. >
  123. Cancel
  124. </a-button>
  125. <a-button @click="onClose" type="primary">Submit</a-button>
  126. </div>
  127. </a-drawer>
  128. </div>
  129. </template>
  130. <script>
  131. export default {
  132. data() {
  133. return {
  134. form: this.$form.createForm(this),
  135. visible: false,
  136. }
  137. },
  138. methods: {
  139. showDrawer() {
  140. this.visible = true
  141. },
  142. onClose() {
  143. this.visible = false
  144. },
  145. },
  146. }
  147. </script>

Drawer抽屉 - 图4

信息预览抽屉

需要快速预览对象概要时使用,点击遮罩区关闭。

  1. <template>
  2. <div>
  3. <a-list
  4. :dataSource="[
  5. {
  6. name: 'Lily',
  7. },
  8. {
  9. name: 'Lily',
  10. },
  11. ]"
  12. bordered
  13. >
  14. <a-list-item slot="renderItem" slot-scope="item, index">
  15. <a slot="actions" @click="showDrawer">View Profile</a>
  16. <a-list-item-meta
  17. description="Progresser AFX"
  18. >
  19. <a slot="title" href="https://vue.ant.design/">{{item.name}}</a>
  20. <a-avatar slot="avatar" src="https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png" />
  21. </a-list-item-meta>
  22. </a-list-item>
  23. </a-list>
  24. <a-drawer
  25. width=640
  26. placement="right"
  27. :closable="false"
  28. @close="onClose"
  29. :visible="visible"
  30. >
  31. <p :style="[pStyle, pStyle2]">User Profile</p>
  32. <p :style="pStyle">Personal</p>
  33. <a-row>
  34. <a-col :span="12">
  35. <description-item title="Full Name" content="Lily" />
  36. </a-col>
  37. <a-col :span="12">
  38. <description-item title="Account" content="AntDesign@example.com" />
  39. </a-col>
  40. </a-row>
  41. <a-row>
  42. <a-col :span="12">
  43. <description-item title="City" content="HangZhou" />
  44. </a-col>
  45. <a-col :span="12">
  46. <description-item title="Country" content="China??" />
  47. </a-col>
  48. </a-row>
  49. <a-row>
  50. <a-col :span="12">
  51. <description-item title="Birthday" content="February 2,1900" />
  52. </a-col>
  53. <a-col :span="12">
  54. <description-item title="Website" content="-" />
  55. </a-col>
  56. </a-row>
  57. <a-row>
  58. <a-col :span="12">
  59. <description-item
  60. title="Message"
  61. content="Make things as simple as possible but no simpler."
  62. />
  63. </a-col>
  64. </a-row>
  65. <a-divider />
  66. <p :style="pStyle">Company</p>
  67. <a-row>
  68. <a-col :span="12">
  69. <description-item title="Position" content="Programmer" />
  70. </a-col>
  71. <a-col :span="12">
  72. <description-item title="Responsibilities" content="Coding" />
  73. </a-col>
  74. </a-row>
  75. <a-row>
  76. <a-col :span="12">
  77. <description-item title="Department" content="AFX" />
  78. </a-col>
  79. <a-col :span="12">
  80. <description-item title="Supervisor" >
  81. <a slot="content">Lin</a>
  82. </description-item>
  83. </a-col>
  84. </a-row>
  85. <a-row>
  86. <a-col :span="24">
  87. <description-item
  88. title="Skills"
  89. content="C / C + +, data structures, software engineering, operating systems, computer networks, databases, compiler theory, computer architecture, Microcomputer Principle and Interface Technology, Computer English, Java, ASP, etc."
  90. />
  91. </a-col>
  92. </a-row>
  93. <a-divider />
  94. <p :style="pStyle">Contacts</p>
  95. <a-row>
  96. <a-col :span="12">
  97. <description-item title="Email" content="ant-design-vue@example.com" />
  98. </a-col>
  99. <a-col :span="12">
  100. <description-item title="Phone Number" content="+86 181 0000 0000" />
  101. </a-col>
  102. </a-row>
  103. <a-row>
  104. <a-col :span="24">
  105. <description-item
  106. title="Github"
  107. >
  108. <a slot='content' href="https://github.com/vueComponent/ant-design-vue">
  109. github.com/vueComponent/ant-design-vue
  110. </a>
  111. </description-item>
  112. </a-col>
  113. </a-row>
  114. </a-drawer>
  115. </div>
  116. </template>
  117. <script>
  118. import descriptionItem from './descriptionItem'
  119. export default {
  120. data() {
  121. return {
  122. visible: false,
  123. pStyle: {
  124. fontSize: '16px',
  125. color: 'rgba(0,0,0,0.85)',
  126. lineHeight: '24px',
  127. display: 'block',
  128. marginBottom: '16px',
  129. },
  130. pStyle2: {
  131. marginBottom: '24px'
  132. }
  133. }
  134. },
  135. components: {
  136. descriptionItem,
  137. },
  138. methods: {
  139. showDrawer() {
  140. this.visible = true
  141. },
  142. onClose() {
  143. this.visible = false
  144. },
  145. },
  146. }
  147. </script>

Drawer抽屉 - 图5

多层抽屉

在抽屉内打开新的抽屉,用以解决多分支任务的复杂状况。

  1. <template>
  2. <div>
  3. <a-button type="primary" @click="showDrawer">
  4. Open
  5. </a-button>
  6. <a-drawer
  7. title="Multi-level drawer"
  8. width=520
  9. :closable="false"
  10. @close="onClose"
  11. :visible="visible"
  12. >
  13. <a-button type="primary" @click="showChildrenDrawer">
  14. Two-level drawer
  15. </a-button>
  16. <a-drawer
  17. title="Two-level Drawer"
  18. width=320
  19. :closable="false"
  20. @close="onChildrenDrawerClose"
  21. :visible="childrenDrawer"
  22. >
  23. <a-button type="primary" @click="showChildrenDrawer">
  24. This is two-level drawer
  25. </a-button>
  26. </a-drawer>
  27. <div
  28. :style="{
  29. position: 'absolute',
  30. bottom: 0,
  31. width: '100%',
  32. borderTop: '1px solid #e8e8e8',
  33. padding: '10px 16px',
  34. textAlign: 'right',
  35. left: 0,
  36. background: '#fff',
  37. borderRadius: '0 0 4px 4px',
  38. }"
  39. >
  40. <a-button
  41. style="marginRight: 8px"
  42. @click="onClose"
  43. >
  44. Cancel
  45. </a-button>
  46. <a-button @click="onClose" type="primary">
  47. Submit
  48. </a-button>
  49. </div>
  50. </a-drawer>
  51. </div>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. visible: false,
  58. childrenDrawer: false
  59. }
  60. },
  61. methods: {
  62. showDrawer() {
  63. this.visible = true
  64. },
  65. onClose() {
  66. this.visible = false
  67. },
  68. showChildrenDrawer() {
  69. this.childrenDrawer = true
  70. },
  71. onChildrenDrawerClose() {
  72. this.childrenDrawer = false
  73. },
  74. },
  75. }
  76. </script>

API

参数说明类型默认值
closable是否显示右上角的关闭按钮booleantrue
destroyOnClose关闭时销毁 Drawer 里的子元素booleanfalse
getContainer指定 Drawer 挂载的 HTML 节点HTMLElement | () => HTMLElement | Selectors'body'
maskClosable点击蒙层是否允许关闭booleantrue
mask是否展示遮罩Booleantrue
maskStyle遮罩样式object{}
title标题string | slot-
visibleDrawer 是否可见boolean-
wrapClassName对话框外层容器的类名string-
wrapStyle对话框外层容器的styleobject-
width宽度string | number256
height高度, 在 placementtopbottom 时使用string | number256
zIndex设置 Drawer 的 z-indexNumber1000
placement抽屉的方向'top' | 'right' | 'bottom' | 'left''right'
handle设置后抽屉直接挂载到DOM上,你可以通过该handle控制抽屉打开关闭VNode | slot-

方法

名称描述类型默认值
close点击遮罩层或右上角叉或取消按钮的回调function(e)