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>
    本人前端水平有限,写的知识点可能有谬误,欢迎留言指正,如果看到,我将第一时间回复。感谢支持!
  • 相关阅读:
    把我给另外一个朋友的炒股劝告发给你一遍,希望你可以得到帮助!
    Microsoft Office Document Imaging批量ocr 方法
    Advanced GET 9.1 修正汉化版(免注册、页面加载、保存都正常)
    波浪分析数据转换:大智慧、钱龙、胜龙可用Advanced GET ToGet 数据转换器V3.05特别版
    怎样精确计算股市主力的持仓量
    混沌理论
    地产联盟内部资料总目录
    C语言 · P1001(大数乘法)
    C语言 · 排列数
    C语言 · 逆序排列
  • 原文地址:https://www.cnblogs.com/qddyh/p/10386403.html
Copyright © 2011-2022 走看看