<template>
<div class="menu-item" @click="isOpen = !isOpen">
<a href="#">
{{ title }}
</a>
<svg viewBox="0 0 1030 638" width="10">
<path d="M1017 68L541 626q-11 12-26 12t-26-12L13 68Q-3 49 6 24.5T39 0h952q24 0 33 24.5t-7 43.5z" fill="#FFF"></path>
</svg>
<transition name="fade" appear>
<div class="sub-menu" v-if="isOpen">
<div v-for="(item, i) in items" :key="i" class="menu-item">
<a :href="item.link">{{ item.title }}</a>
</div>
</div>
</transition>
</div>
</template>
<script>
export default {
name: 'dropdown',
props: ['title', 'items'],
data () {
return {
isOpen: false
}
}
}
</script>
<style>
nav .menu-item svg {
width: 10px;
margin-left: 10px;
}
nav .menu-item .sub-menu {
position: absolute;
background-color: #222;
top: calc(100% + 18px);
left: 50%;
transform: translateX(-50%);
width: max-content;
border-radius: 0px 0px 16px 16px;
}
.fade-enter-active,
.fade-leave-active {
transition: all .5s ease-out;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
</style>
<template>
<nav>
<div class="menu-item"><a href="#">点赞</a></div>
<div class="menu-item"><a href="#">投币</a></div>
<Dropdown title="关注" :items="关注" />
<div class="menu-item"><a href="#">收藏</a></div>
</nav>
</template>
<script>
import Dropdown from './Dropdown';
export default {
name: '关注',
components: {
Dropdown
},
data () {
return {
'关注': [
{
title: '少轻狂',
link: 'https://space.bilibili.com/237173875/'
},
{
title: '敏捷开发',
link:'https://space.bilibili.com/237173875/'
},
{
title: '导航栏',
link: 'https://space.bilibili.com/237173875/'
}
]
}
}
}
</script>
<style>
nav {
display: flex;
align-items: center;
justify-content: center;
}
nav .menu-item {
color: #FFF;
padding: 10px 20px;
position: relative;
text-align: center;
border-bottom: 3px solid transparent;
display: flex;
transition: 0.4s;
}
nav .menu-item.active,
nav .menu-item:hover {
background-color: #444;
border-bottom-color: #FF5858;
}
nav .menu-item a {
color: inherit;
text-decoration: none;
}
</style>