当前位置:   article > 正文

Vue3实现抽屉效果_vue抽屉效果展开收起

vue抽屉效果展开收起

Darwer.vue

  1. <template>
  2. <div class="drawer">
  3. <!-- 遮罩层 -->
  4. <div class="mask-show" v-if="drawerShow" @click="close()"></div>
  5. <!-- 抽屉层 -->
  6. <div class="darwer-box" :class="{ show: drawerShow }"></div>
  7. </div>
  8. </template>
  9. <script setup>
  10. import { watch, reactive, defineProps, defineEmits } from 'vue'
  11. const emits = defineEmits(['handleCloseDialog'])
  12. const props = defineProps({
  13. drawerShow: {
  14. type: Boolean,
  15. default: false,
  16. },
  17. })
  18. watch(
  19. () => props.drawerShow,
  20. () => {
  21. dataDarw.drawerShow = props.drawerShow
  22. }
  23. )
  24. const dataDarw = reactive({
  25. drawerShow: props.drawerShow,
  26. })
  27. const close = () => {
  28. emits('handleCloseDialog', false)
  29. }
  30. watch(
  31. () => props.data,
  32. (val) => {
  33. props.data = val
  34. },
  35. { deep: true }
  36. )
  37. </script>
  38. <style lang="scss" scoped>
  39. .drawer {
  40. width: 100%;
  41. display: flex;
  42. display: -webkit-flex;
  43. flex-direction: column;
  44. .mask-show {
  45. width: 100%;
  46. height: 100%;
  47. background: rgb(0, 0, 0, 0.5);
  48. position: fixed;
  49. z-index: 100;
  50. top: 0;
  51. left: 0;
  52. right: 0;
  53. bottom: 0;
  54. backface-visibility: hidden;
  55. }
  56. .darwer-box {
  57. padding: 20px;
  58. position: fixed;
  59. z-index: 1100;
  60. top: 0px;
  61. bottom: 0px;
  62. width: 60%;
  63. height: calc(100% - 40px);
  64. background: linear-gradient(
  65. 312.9deg,
  66. rgba(255, 255, 255, 0.3) 4.49%,
  67. rgba(233, 240, 247, 0.3) 95.45%
  68. ),
  69. #e9f0f7;
  70. border-left: 1px solid #cfd8dc !important;
  71. box-shadow: 0px 3px 12px rgba(0, 0, 0, 0.12);
  72. -webkit-transition: all 1s ease;
  73. transition: all 1s ease;
  74. right: -62%;
  75. overflow-y: auto;
  76. }
  77. .show {
  78. right: 0;
  79. }
  80. }
  81. </style>

引用组件

index.vue

  1. <template>
  2. <el-button @click='show'>show-darwer</el-button>
  3. <BaseModalDrawer
  4. :visibleModal="data.visibleModal"
  5. @handleCloseDialog=handleCloseDialog
  6. ></BaseModalDrawer>
  7. </template>
  8. <script setup>
  9. import {reactive } from 'vue'
  10. import BaseModalDrawer from '../common/BaseModalDrawer.vue'
  11. const data = reactive({
  12. visibleModal:false
  13. })
  14. const show = ()=>{
  15. data.visibleModal = true
  16. }
  17. const handleCloseDialog = ()=>{
  18. data.visibleModal = false
  19. }
  20. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/43214?site
推荐阅读
  

闽ICP备14008679号