Vue3实现抽屉效果

Darwer.vue

<template>
	<div class="drawer">
		<!-- 遮罩层 -->
		<div class="mask-show" v-if="drawerShow" @click="close()"></div>
		<!-- 抽屉层 -->
		<div class="darwer-box" :class="{ show: drawerShow }"></div>
	</div>
</template>
<script setup>
import { watch, reactive, defineProps, defineEmits } from 'vue'

const emits = defineEmits(['handleCloseDialog'])

const props = defineProps({
	drawerShow: {
		type: Boolean,
		default: false,
	},
})

watch(
	() => props.drawerShow,
	() => {
		dataDarw.drawerShow = props.drawerShow
	}
)

const dataDarw = reactive({
	drawerShow: props.drawerShow,
})

const close = () => {
	emits('handleCloseDialog', false)
}

watch(
	() => props.data,
	(val) => {
		props.data = val
	},
	{ deep: true }
)
</script>
<style lang="scss" scoped>
.drawer {
	width: 100%;
	display: flex;
	display: -webkit-flex;
	flex-direction: column;
	.mask-show {
		width: 100%;
		height: 100%;
		background: rgb(0, 0, 0, 0.5);
		position: fixed;
		z-index: 100;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		backface-visibility: hidden;
	}
	.darwer-box {
		padding: 20px;
		position: fixed;
		z-index: 1100;
		top: 0px;
		bottom: 0px;
		width: 60%;
		height: calc(100% - 40px);

		background: linear-gradient(
				312.9deg,
				rgba(255, 255, 255, 0.3) 4.49%,
				rgba(233, 240, 247, 0.3) 95.45%
			),
			#e9f0f7;
		border-left: 1px solid #cfd8dc !important;
		box-shadow: 0px 3px 12px rgba(0, 0, 0, 0.12);
		-webkit-transition: all 1s ease;
		transition: all 1s ease;
		right: -62%;
		overflow-y: auto;
	}
	.show {
		right: 0;
	}
}

</style>

引用组件

index.vue

<template>
<el-button @click='show'>show-darwer</el-button>
<BaseModalDrawer
			:visibleModal="data.visibleModal"
			@handleCloseDialog=handleCloseDialog
		></BaseModalDrawer>
</template>

<script setup>
import {reactive } from 'vue'
import BaseModalDrawer from '../common/BaseModalDrawer.vue' 

const data = reactive({
visibleModal:false
})
const show = ()=>{
data.visibleModal = true
}
const handleCloseDialog = ()=>{
	data.visibleModal = false
}
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值