1. <template>
    2. <v-app-bar app :class="navClass" hide-on-scroll flat height="60">
    3. <!-- 手机端导航栏 -->
    4. <div class="d-md-none nav-mobile-container">
    5. <div style="font-size: 18px; font-weight: bold">
    6. <router-link to="/"> 星之卡比 </router-link>
    7. </div>
    8. <div style="margin-left: auto">
    9. <a><i class="iconfont iconsousuo" /></a>
    10. <a @click="openDrawer" style="margin-left: 10px; font-size: 20px">
    11. <i class="iconfont iconhanbao" />
    12. </a>
    13. </div>
    14. </div>
    15. <!-- 电脑导航栏 -->
    16. <div class="d-md-block d-none nav-container">
    17. <div class="float-left blog-title">
    18. <router-link to="/"> 星之卡比 </router-link>
    19. </div>
    20. <div class="float-right nav-title">
    21. <div class="menus-btn">
    22. <a><i class="iconfont iconsousuo" /> 搜索</a>
    23. </div>
    24. <div class="menus-item">
    25. <router-link to="/">
    26. <i class="iconfont iconzhuye" /> 首页
    27. </router-link>
    28. </div>
    29. <div class="menus-item">
    30. <router-link to="/archives">
    31. <i class="iconfont iconguidang" /> 归档
    32. </router-link>
    33. </div>
    34. <div class="menus-item">
    35. <router-link to="/categories">
    36. <i class="iconfont iconfenlei" /> 分类
    37. </router-link>
    38. </div>
    39. <div class="menus-item">
    40. <router-link to="/tags">
    41. <i class="iconfont iconbiaoqian" /> 标签
    42. </router-link>
    43. </div>
    44. <div class="menus-item">
    45. <router-link to="/links">
    46. <i class="iconfont iconlianjie" /> 友链
    47. </router-link>
    48. </div>
    49. <div class="menus-item">
    50. <router-link to="/about">
    51. <i class="iconfont iconzhifeiji" /> 关于
    52. </router-link>
    53. </div>
    54. <div class="menus-item">
    55. <router-link to="/message">
    56. <i class="iconfont iconpinglunzu" /> 留言
    57. </router-link>
    58. </div>
    59. <div class="user-btn">
    60. <a v-if="!this.$store.state.avatar">
    61. <i class="iconfont icondenglu" /> 登录
    62. </a>
    63. <template v-else>
    64. <img
    65. class="user-avatar"
    66. :src="this.$store.state.avatar"
    67. height="30"
    68. width="30"
    69. />
    70. <ul class="user-submenu">
    71. <li>
    72. <router-link to="/user">
    73. <i class="iconfont icongerenzhongxin" /> 个人中心
    74. </router-link>
    75. </li>
    76. <li>
    77. <a><i class="iconfont icontuichu" /> 退出</a>
    78. </li>
    79. </ul>
    80. </template>
    81. </div>
    82. </div>
    83. </div>
    84. </v-app-bar>
    85. </template>
    86. <script>
    87. export default {
    88. mounted() {
    89. window.addEventListener("scroll", this.scroll);
    90. },
    91. data: function () {
    92. return {
    93. navClass: "",
    94. };
    95. },
    96. methods: {
    97. scroll() {
    98. const that = this;
    99. let scrollTop =
    100. window.pageYOffset ||
    101. document.documentElement.scrollTop ||
    102. document.body.scrollTop;
    103. that.scrollTop = scrollTop;
    104. if (that.scrollTop > 60) {
    105. that.navClass = "nav-fixed";
    106. } else {
    107. that.navClass = "nav";
    108. }
    109. },
    110. openDrawer() {
    111. this.$store.state.drawer = true;
    112. },
    113. },
    114. computed: {
    115. avatar() {
    116. return this.$store.state.avatar;
    117. },
    118. },
    119. };
    120. </script>
    121. <style scoped>
    122. i {
    123. margin-right: 4px;
    124. }
    125. ul {
    126. list-style: none;
    127. }
    128. .nav {
    129. background: rgba(0, 0, 0, 0) !important;
    130. }
    131. .nav a {
    132. color: #eee !important;
    133. }
    134. .nav .menus-item a {
    135. text-shadow: 0.05rem 0.05rem 0.1rem rgba(0, 0, 0, 0.3);
    136. }
    137. .nav .blog-title a {
    138. text-shadow: 0.1rem 0.1rem 0.2rem rgba(0, 0, 0, 0.15);
    139. }
    140. .theme--light.nav-fixed {
    141. background: rgba(255, 255, 255, 0.8) !important;
    142. box-shadow: 0 5px 6px -5px rgba(133, 133, 133, 0.6);
    143. }
    144. .theme--dark.nav-fixed {
    145. background: rgba(18, 18, 18, 0.8) !important;
    146. }
    147. .theme--dark.nav-fixed a {
    148. color: rgba(255, 255, 255, 0.8) !important;
    149. }
    150. .theme--light.nav-fixed a {
    151. color: #4c4948 !important;
    152. }
    153. .nav-fixed .menus-item a,
    154. .nav-fixed .menus-btn a,
    155. .nav-fixed .blog-title a {
    156. text-shadow: none;
    157. }
    158. .nav-container {
    159. font-size: 14px;
    160. width: 100%;
    161. height: 100%;
    162. }
    163. .nav-mobile-container {
    164. width: 100%;
    165. display: flex;
    166. align-items: center;
    167. }
    168. .blog-title,
    169. .nav-title {
    170. display: flex;
    171. align-items: center;
    172. height: 100%;
    173. }
    174. .blog-title a {
    175. font-size: 18px;
    176. font-weight: bold;
    177. }
    178. .user-btn,
    179. .menus-btn,
    180. .menus-item {
    181. position: relative;
    182. display: inline-block;
    183. margin: 0 0 0 0.875rem;
    184. }
    185. .menus-btn a,
    186. .menus-item a {
    187. transition: all 0.2s;
    188. }
    189. .nav-fixed .menus-btn a:hover,
    190. .nav-fixed .menus-item a:hover {
    191. color: #49b1f5 !important;
    192. }
    193. .menus-item a:hover:after {
    194. width: 100%;
    195. }
    196. .menus-item a:after {
    197. position: absolute;
    198. bottom: -5px;
    199. left: 0;
    200. z-index: -1;
    201. width: 0;
    202. height: 3px;
    203. background-color: #80c8f8;
    204. content: "";
    205. transition: all 0.3s ease-in-out;
    206. }
    207. .user-btn a {
    208. transition: all 0.2s;
    209. }
    210. .user-avatar {
    211. cursor: pointer;
    212. border-radius: 50%;
    213. }
    214. .user-btn:hover .user-submenu {
    215. display: block;
    216. }
    217. .user-submenu {
    218. position: absolute;
    219. display: none;
    220. right: 0;
    221. width: max-content;
    222. margin-top: 8px;
    223. box-shadow: 0 5px 20px -4px rgba(0, 0, 0, 0.5);
    224. background-color: #fff;
    225. animation: submenu 0.3s 0.1s ease both;
    226. }
    227. .user-submenu:before {
    228. position: absolute;
    229. top: -8px;
    230. left: 0;
    231. width: 100%;
    232. height: 20px;
    233. content: "";
    234. }
    235. .user-submenu a {
    236. line-height: 2;
    237. color: #4c4948 !important;
    238. text-shadow: none;
    239. display: block;
    240. padding: 6px 14px;
    241. }
    242. .user-submenu a:hover {
    243. background: #4ab1f4;
    244. }
    245. @keyframes submenu {
    246. 0% {
    247. opacity: 0;
    248. filter: alpha(opacity=0);
    249. transform: translateY(10px);
    250. }
    251. 100% {
    252. opacity: 1;
    253. filter: none;
    254. transform: translateY(0);
    255. }
    256. }
    257. </style>