Vue3后台管理系统Hamburger组件
在Vue 3中创建一个名为Hamburger.vue
的组件,用于实现一个用于切换侧边栏显示状态的按钮。
<template>
<div class="hamburger" :class="{ 'is-active': isActive }" @click="toggle">
<div class="hamburger-box">
<div class="hamburger-inner"></div>
</div>
</div>
</template>
<script>
export default {
name: 'Hamburger',
props: {
isActive: {
type: Boolean,
required: true
}
},
methods: {
toggle() {
this.$emit('toggle');
}
}
};
</script>
<style scoped>
.hamburger {
cursor: pointer;
transition-property: opacity, filter;
transition-duration: 300ms;
transition-timing-function: linear;
font: inherit;
color: inherit;
background-color: transparent;
margin: 0;
padding: 0;
display: inline-block;
overflow: visible;
}
.hamburger-box {
display: inline-block;
position: relative;
font-size: 24px;
width: 40px;
height: 40px;
transition: transform 0.3s ease;
}
.hamburger-inner {
display: block;
top: 50%;
width: 40px;
height: 2px;
margin-top: -1px;
background-color: #000;
transition: transform 0.3s ease;
}
.hamburger.is-active .hamburger-inner {
transform: translate3d(0, -50%, 0) rotate(90deg);
transition-delay: 150ms;
}
</style>
这个Hamburger.vue
组件包含一个hamburger图标,当它被点击时,会发出一个toggle
事件,可以被父组件监听并作出响应(比如切换侧边栏的显示状态)。.is-active
类用于改变hamburger图标的样式,表示侧边栏当前是展开还是折叠状态。
评论已关闭