[Vue]自定义导航栏
思路留存自用,主要是template部分,效果大概如下:
<template> <div v-show="isStart" :class="'menu_page' + aniClass"> <div class="menu" v-for="item in items"> <div class="group" v-if="item.children" :index="item.path" :key="item.path"> <div class="title"> <div class="shortline"></div>{{ item.name }} </div> <div class="tags"> <router-link class="tag_item" v-for="(citem, cindex) in item.children" :to="citem.path" :key="cindex"> <img class="tag-icon" :src="citem.icon" />{{ citem.name }} </router-link> </div> </div> </div> </div> </template> <script> export default { name: 'left-menu', data() { return { isStart: false, isOut: true, aniClass: '', items: [ { name: '大标题1', path: 'path1', children: [ { path: 'path1-1', name: '小标题1-1', icon: require('../../assets/svg/nav/icon.svg') }, { path: 'path1-1', name: '小标题1-2', icon: require('../../assets/svg/nav/icon.svg') }, { path: 'path1-1', name: '小标题1-3', icon: require('../../assets/svg/nav/icon.svg') }, ], }, { name: '大标题2', path: 'exchange', children: [ { path: 'path2-1', name: '小标题2-1', icon: require('../../assets/svg/nav/icon.svg') }, ], }, { name: '大标题3', path: 'path3', children: [ { path: 'path3-1', name: '小标题3-1', icon: require('../../assets/svg/nav/icon.svg') }, ], }, ], } }, methods: { show() { this.isStart = true this.isOut = !this.isOut this.aniClass = this.isOut ? ' move_out' : ' move_in' } } } </script> <style lang="scss" scoped> /* 自定义 */ .menu { position: relative; left: 0; min-height: 100px; background-color: rgba(0, 20, 50, 0.8); } .group { position: relative; width: inherit; .title { display: inline-block; padding: 20px 0 10px 0; font-weight: 700; font-style: normal; font-size: 20px; color: #FFFFFF; line-height: 18px; .shortline { display: inline-block; width: 3px; height: 18px; background-color: rgba(122, 196, 253, 1); margin: -2px 8px; } } .tags { width: 380px; // 一行3个:380px; 一行4个:500px display: flex; justify-content: flex-start; // align-items: flex-start; flex-wrap: wrap; .tag_item { width: 100px; height: 68px; background-color: rgba(15, 56, 117, 0.8); border: none; border-radius: 6px; margin: 10px 12px; color: #7AC4FD; text-align: center; line-height: 18px; cursor: pointer; .tag-icon { display: block; margin: 10px auto; } } .tag_item:hover { color: #FFFFFF; } } } .move_in { animation-duration: 1s; animation-fill-mode: forwards; animation-name: slidein; } @keyframes slidein { from { transform: translate(-500px, 0); } to { transform: translate(0, 0); } } .move_out { animation-duration: 1s; animation-fill-mode: forwards; animation-name: slideout; } @keyframes slideout { from { transform: translate(0, 0); } to { transform: translate(-500px, 0); } } </style>