最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue3導(dǎo)航欄組件封裝實(shí)現(xiàn)方法

 更新時(shí)間:2021年09月14日 14:26:29   作者:丹丹呀~~  
這篇文章主要為大家詳細(xì)介紹了Vue3導(dǎo)航欄組件封裝的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

在Vue3中封裝一個(gè)導(dǎo)航欄組件,并且實(shí)現(xiàn),隨著滾動(dòng)條滾動(dòng)實(shí)現(xiàn)一個(gè)吸頂效果,供大家參考

導(dǎo)航欄組件的效果圖:

滾動(dòng)條滾動(dòng)以后的吸頂效果示意圖:

具體代碼展示:

<template>
  <header class="app-header">
    <div class="container">
      <!-- 頭部導(dǎo)航區(qū)域 -->
      <HeaderNavCommon />
      <div class="search">
        <i class="iconfont icon-search"></i>
        <input type="text" placeholder="搜一搜" />
      </div>
      <div class="cart">
        <a href="#" class="curr">
          <i class="iconfont icon-cart"></i>
          <em>2</em>
        </a>
      </div>
    </div>
  </header>
</template>
 
<script>
import HeaderNavCommon from '@/components/header-nav-common.vue'
export default {
  name: 'AppHeader',
  components: {
    HeaderNavCommon
  }
}
</script>
 
<style scoped lang="less">
.app-header {
  background: #fff;
  .container {
    display: flex;
    align-items: center;
  }
  .navs {
    width: 820px;
    display: flex;
    justify-content: space-around;
    padding-left: 40px;
    li {
      margin-right: 40px;
      width: 38px;
      text-align: center;
      a {
        display: inline-block;
        font-size: 16px;
        line-height: 32px;
        height: 32px;
      }
      &:hover {
        a {
          color: @xtxColor;
          border-bottom: 1px solid @xtxColor;
        }
      }
    }
  }
  .search {
    width: 170px;
    height: 32px;
    position: relative;
    border-bottom: 1px solid #e7e7e7;
    line-height: 32px;
    .icon-search {
      font-size: 18px;
      margin-left: 5px;
    }
    input {
      width: 140px;
      padding-left: 5px;
      color: #666;
    }
  }
  .cart {
    width: 50px;
    .curr {
      height: 32px;
      line-height: 32px;
      text-align: center;
      position: relative;
      display: block;
      .icon-cart {
        font-size: 22px;
      }
      em {
        font-style: normal;
        position: absolute;
        right: 0;
        top: 0;
        padding: 1px 6px;
        line-height: 1;
        background: @helpColor;
        color: #fff;
        font-size: 12px;
        border-radius: 10px;
        font-family: Arial;
      }
    }
  }
}
</style>

中間菜單部門單獨(dú)封裝一個(gè)組件,實(shí)現(xiàn)兩個(gè)組件的復(fù)用  (HeaderNavCommon組件)

<template>
  <ul class="app-header-nav">
    <li class="home"><RouterLink to="/">首頁(yè)</RouterLink></li>
    <li><a href="#" >美食</a></li>
    <li><a href="#" >餐廚</a></li>
    <li><a href="#" >藝術(shù)</a></li>
    <li><a href="#" >電器</a></li>
    <li><a href="#" >居家</a></li>
    <li><a href="#" >洗護(hù)</a></li>
    <li><a href="#" >孕嬰</a></li>
    <li><a href="#" >服裝</a></li>
    <li><a href="#" >雜貨</a></li>
  </ul>
</template>
 
<script>
 export default {
    name: 'AppHeaderNav'
   }
</script>
 
<style scoped lang='less'>
.app-header-nav {
    width: 820px;
    display: flex;
    padding-left: 40px;
    position: relative;
    z-index: 998;
  li {
    margin-right: 40px;
    width: 38px;
    text-align: center;
  a {
    font-size: 16px;
    line-height: 32px;
    height: 32px;
    display: inline-block;
   }
  &:hover {
    a {
    color: @xtxColor;
    border-bottom: 1px solid @xtxColor;
        }
      }
  }
}
</style>

封裝吸頂效果的組件

<template>
  <div class="app-header-sticky" :class="{ show: top >= 78 }">
    <div class="container" v-if="top >= 78">
      <!-- 中間 -->
      <HeaderNavCommon />
      <!-- 右側(cè)按鈕 -->
      <div class="right">
        <RouterLink to="/">品牌</RouterLink>
        <RouterLink to="/">專題</RouterLink>
      </div>
    </div>
  </div>
</template>
 
<script>
import HeaderNavCommon from '@/components/header-nav-common.vue'
// import { ref } from 'vue'
import { useWindowScroll } from '@vueuse/core'
export default {
  name: 'AppHeaderSticky',
  components: { HeaderNavCommon },
  setup() {
    // 頁(yè)面滾動(dòng)距離
    // const top = ref(0)
    // window.onscroll = () => {
    //   top.value = document.documentElement.scrollTop
    // }
    // 頁(yè)面滾動(dòng)利用第三方包
    const { y: top } = useWindowScroll()
    return { top }
  }
}
</script>
 
<style scoped lang="less">
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  // 此處為關(guān)鍵樣式!!!
  // 默認(rèn)情況下完全把自己移動(dòng)到上面
  transform: translateY(-100%);
  // 完全透明
  opacity: 0;
  // 顯示出來(lái)的類名
  &.show {
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }
  .container {
    display: flex;
    align-items: center;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue-router的導(dǎo)航守衛(wèi)使用最新講解

    vue-router的導(dǎo)航守衛(wèi)使用最新講解

    這篇文章主要介紹了vue-router的導(dǎo)航守衛(wèi)使用講解,vue-router提供了許多編程式導(dǎo)航的API,其中最常見的導(dǎo)航API有很多種,本文給大家詳細(xì)講解,需要的朋友可以參考下
    2022-12-12
  • 前端Vue學(xué)習(xí)之購(gòu)物車項(xiàng)目實(shí)戰(zhàn)記錄

    前端Vue學(xué)習(xí)之購(gòu)物車項(xiàng)目實(shí)戰(zhàn)記錄

    購(gòu)物車是電商必備的功能,可以讓用戶一次性購(gòu)買多個(gè)商品,下面這篇文章主要給大家介紹了關(guān)于前端Vue學(xué)習(xí)之購(gòu)物車項(xiàng)目的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-07-07
  • Vue前端高效開發(fā)之列表渲染指令

    Vue前端高效開發(fā)之列表渲染指令

    這篇文章主要給大家介紹了關(guān)于Vue前端高效開發(fā)之列表渲染指令的相關(guān)資料,vue.js 使用的是 v-for 指令來(lái)處理組件元素的循環(huán)迭代邏輯,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-06-06
  • 如何在vue單頁(yè)中重復(fù)引入同一子組件

    如何在vue單頁(yè)中重復(fù)引入同一子組件

    這篇文章主要介紹了如何在vue單頁(yè)中重復(fù)引入同一子組件問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue?button的@click方法無(wú)效鉤子函數(shù)沒有執(zhí)行問題

    vue?button的@click方法無(wú)效鉤子函數(shù)沒有執(zhí)行問題

    這篇文章主要介紹了vue?button的@click方法無(wú)效鉤子函數(shù)沒有執(zhí)行問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 詳解vuex狀態(tài)管理模式

    詳解vuex狀態(tài)管理模式

    這篇文章主要介紹了詳解vuex狀態(tài)管理模式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • vue translate peoject實(shí)現(xiàn)在線翻譯功能【新手必看】

    vue translate peoject實(shí)現(xiàn)在線翻譯功能【新手必看】

    這篇文章主要介紹了vue translate peoject實(shí)現(xiàn)在線翻譯功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-06-06
  • 對(duì) Vue-Router 進(jìn)行單元測(cè)試的方法

    對(duì) Vue-Router 進(jìn)行單元測(cè)試的方法

    這篇文章主要介紹了對(duì) Vue-Router 進(jìn)行單元測(cè)試的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Vue.js directive自定義指令詳解

    Vue.js directive自定義指令詳解

    這篇文章主要介紹了Vue.js directive自定義指令詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • Vue2.0腳手架搭建

    Vue2.0腳手架搭建

    這篇文章介紹了使用vue-cli搭建腳手架的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03

最新評(píng)論

平凉市| 抚松县| 盖州市| 仙居县| 彭山县| 大悟县| 江津市| 崇信县| 平陆县| 蓬莱市| 长垣县| 沾益县| 论坛| 遂宁市| 渭南市| 长沙县| 璧山县| 宜良县| 嘉鱼县| 池州市| 中卫市| 瓦房店市| 霸州市| 南华县| 洪湖市| 南阳市| 梧州市| 弋阳县| 霍州市| 洪湖市| 温宿县| 资阳市| 克什克腾旗| 介休市| 滨州市| 凌海市| 虞城县| 达孜县| 普兰县| 罗城| 通山县|