zoukankan      html  css  js  c++  java
  • vue实用组件——页面公共头部

    可伸缩自适应的页面头部,屏幕适应范围更广泛

    效果如下:

    代码如下:

    <template>
    <div class="site-header">
    <div class="logo"><img src="@/assets/icons/logo.png" alt=""></div>
    <nav class="title">
    <!--汉堡按钮图标-->
    <em class="iconfont icon-justify" @click.stop="toggle('title')"></em>
    <ul ref="title">
    <li class="active">
    <a href="#">{{ 首页}}</a>
    </li>
    <li>
    <a href="#">{{ 交易中心}}</a>
    </li>
    <li>
    <a href="#">{{ 用户中心}}</a>
    </li>
    <li>
    <a href="#">{{ 新闻 }}</a>
    </li>
    <li>
    <a href="#">{{ 关于我们 }}</a>
    </li>
    </ul>
    </nav>
    <div class="aboutlogin">
    <!--用户头像图标-->
    <em class="iconfont icon-user" @click.stop="toggle('aboutlogin')"></em>
    <ul ref="aboutlogin">
    <li class="active">
    <a href="#">{{ 登录 }}</a>
    </li>
    <li>
    <a href="#">{{ 注册}}</a>
    </li>
    <li v-if="false"><a href="javascript:;">{{ 欢迎 }}</a>&nbsp;&nbsp;<span>{{ 555 }}</span></li>
    <li v-if="false">
    <a href="javascript:;">{{退出}}</a>
    </li>
    </ul>
    </div>
    </div>
    </template>

    <script>
    export default {
    computed: {
    clickRootNum () {
    return this.$store.state.system.clickRootNum
    }
    },
    methods: {
    toggle (ref) {
    if (ref === 'title') {
    this.$refs.aboutlogin.classList.remove('d-show')
    } else {
    this.$refs.title.classList.remove('d-show')
    }
    const ele = this.$refs[ref]
    const classname = ele.className
    if (classname.indexOf('d-show') > -1) {
    ele.classList.remove('d-show')
    } else {
    ele.classList.add('d-show')
    }
    }
    },
    watch: {
    'clickRootNum' () { // 点击页面任意位置关闭下拉列表,需要vuex的状态来配合
    this.$refs.title.classList.remove('d-show')
    this.$refs.aboutlogin.classList.remove('d-show')
    }
    }
    }
    </script>

    <style scoped lang="scss">
    /*定义的一些主题颜色*/
    @import "../../assets/css/variate";

    .d-show {display: block!important;}
    @media screen and (min- 781px) {
    .site-header{
    height: 72px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    border-bottom: 1px solid $themecolor;
    background-color: #fff;
    align-items: center;
    .logo{
    margin-left: 10px;
    height: 52px;
    }
    .aboutlogin{
    250px;
    height: 100%;
    margin-right: 10px;
    .icon-user {
    display: none;
    }
    ul {
    display: flex!important;
    flex-direction: row;
    justify-content: space-around;
    li{
    display: inline-block;
    line-height: 72px;
    font-size: 14px;
    cursor: pointer;
    color: #7a7a7a;
    &:hover>a {
    color: $themecolor;
    }
    a {
    color: #7a7a7a;
    display: inline-block;
    &:active{
    transform: translateY(1px);
    }
    }
    &.active a{
    color: $themehover;
    font-weight: bold;
    }
    }
    }
    }
    .title {
    600px;
    margin: 0 20px;
    .icon-justify {
    display: none;
    }
    ul {
    display: flex!important;
    flex-direction: row;
    justify-content: space-between;
    li {
    display: inline-block;
    line-height: 72px;
    &:hover a{
    background-color: $themecolor;
    padding: 2px 5px;
    color: #fff;
    }
    a{
    color: $themecolor;
    font-size: 18px;
    padding: 2px 5px;
    &:active {
    background-color: $themehover;
    }
    }
    &.active a{
    background-color: $themecolor;
    color: #fff;
    }
    }
    }
    }
    }
    }
    @media screen and (max- 780px) {
    .site-header{
    height: 72px;
    border-bottom: 1px solid $themecolor;
    background-color: #fff;
    position: relative;
    .logo{
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto 0;
    right: 10px;
    height: 52px;
    }
    .aboutlogin{
    60px;
    height: 100%;
    margin-right: 10px;
    position: absolute;
    left: 60px;
    .icon-user {
    font-size: 32px;
    color: #999;
    line-height: 72px;
    display: inline-block;
    cursor: pointer;
    }
    ul {
    display: none;
    background-color: #fff;
    position: absolute;
    left: -10px;
    top: 71px;
    90px;
    li{
    line-height: 36px;
    font-size: 14px;
    cursor: pointer;
    padding-left: 10px;
    color: #7a7a7a;
    &:hover>a {
    color: $themecolor;
    }
    a {
    color: #7a7a7a;
    display: inline-block;
    &:active{
    transform: translateY(1px);
    }
    }
    }
    }
    }
    .title {
    60px;
    position: absolute;
    left: 10px;
    .icon-justify {
    font-size: 32px;
    line-height: 72px;
    display: inline-block;
    cursor: pointer;
    }
    ul {
    display: none;
    position: absolute;
    left: -10px;
    top: 71px;
    120px;
    background-color: #fff;
    li {
    line-height: 36px;
    padding-left: 6px;
    &:hover a{
    background-color: $themecolor;
    color: #fff;
    }
    a{
    color: $themecolor;
    padding: 0 6px;
    font-size: 18px;
    &:active {
    background-color: $themehover;
    }
    }
    &.active a{
    background-color: $themecolor;
    color: #fff;
    }
    }
    }
    }
    }
    }
    </style>
    本人前端水平有限,写的知识点可能有谬误,欢迎留言指正,如果看到,我将第一时间回复。感谢支持!
  • 相关阅读:
    [转]Visual Studio 2005中绝对定位控件的问题
    ado.net连sql2005的问题
    sql2005 清除日志
    【转帖】OnPreRender Render的区别
    sql2005锁,隔离级别等一些相关问题(一)
    获得远程文件MediaType
    jQuery学习教程 基础篇 归档
    PHP.ini Zend Debugger
    HTML5视频方案:支持iPad Safari、Firefox、Chrome、IE9876
    AS3 流媒体历史记录实现
  • 原文地址:https://www.cnblogs.com/qddyh/p/10386403.html
Copyright © 2011-2022 走看看