自定义抽屉组件

本文介绍了一个自定义的抽屉组件的源代码,该组件支持左右滑动效果,可设置宽度,并提供了关闭回调功能。通过修改`isshow`属性控制显示和隐藏,`type`属性设置抽屉滑出方向,`width`属性设置抽屉宽度。在实际项目中,可以方便地引入并使用此组件来创建具有滑动效果的侧边栏。
摘要由CSDN通过智能技术生成

自定义抽屉组件


源代码代码
	<template>
  <div class="">
    <div class="setbox" :class="isshow ? showClass : ''" :style="drawerStyle">
      <div class="content">
        <div class="close" :class="type=='left'?'left':'right'" @click="close">
          <i v-if="type=='left'" :class="isshow?'el-icon-d-arrow-left':'el-icon-d-arrow-right'"></i>
          <i v-else :class="isshow?'el-icon-d-arrow-right':'el-icon-d-arrow-left'"></i>
        </div>
        <slot></slot>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "demo",
  props: {
    isshow: {
      type: Boolean,
      default: false,
    },
    type: {
      type: String,
      default: "left",
    },
    width: {
      type: Number,
      default: 275,
    },
  },
  computed: {
    drawerStyle() {
      return this.type == "left"
        ? {
            width: `${this.width}px`,
            left: `-${this.width-56}px`,
          }
        : {
            width: `${this.width}px`,
            right: `-${this.width}px`,
          };
    },
    showClass() {
      return this.type == "left" ? "show-left" : "show-right";
    },
  },
  data() {
    return {
      //   isshow: false,
    };
  },
  methods: {
    close() {
      this.$emit("close");
    },
  },
};
</script>
<style lang="scss" scoped>
.setbox {
  position: fixed;
  z-index: 99;
  top: 90px;
  bottom: 0px;
  width: 275px;
  height: 100%;
  background: #25262a;
  border: 2px solid #010112;
  box-shadow: 0px 3px 12px rgba(0, 0, 0, 0.12);
  border-top: none;
  border-bottom: none;
  -webkit-transition: all 0.3s ease;
  transition: all 0.3s ease; //过渡属性
  //   left: -275px;
  .content {
    width: 100%;
    height: 100%;
    position: relative;
  }
  .close {
    position: absolute;
    top: 0;
    width: 28px;
    height: 30px;
    background: #25262a;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid #010112;
    &.left {
      right: -30px;
      border-radius: 0px 6px 6px 0px;
    }
    &.right {
      border-radius: 6px 0px 0px 6px;
      left: -30px;
    }
    i {
      color: #9a9a9a;
    }
  }
}
.show-left {
  left: 55px !important;
}
.show-right {
  right: 0 !important;
}
</style>

使用
    <drawer :isshow="isshow1" @close="close1" type="right">
      <span style="color: #fff">123123</span>
    </drawer>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值