vue?底部footer導航組件問題
Vue底部footer導航組件
底部導航一定要用路徑!!! 賊關鍵
舉個例子:
你隨便定義了一個變量, flag : 0 跳轉首頁, falg:1,跳轉我的,
底部導航的組件不可能全項目使用, 點擊我的頁面 這個時候flag 已經(jīng)變成了1,
從我的頁面進入詳情頁,從詳情頁返回的時候,雖然路由沒有變,但是flag 已經(jīng)初始化成了0,
我們的判斷條件沒辦法自定義,每次從詳情頁返回的時候都會被初始化,
!!! 判斷一定要用路徑
$route.path
<template> <div class="footer"> <div class="costList1" @click="choiceState('/dashboard/Analysis')"> <img class="costUrl" v-if="$route.path==='/dashboard/analysis'" src="../../assets/img/bot-apply0.png" /> <img class="costUrl" v-else src="../../assets/img/bot-apply1.png" /> <div class="costName" :style="{color:$route.path==='/dashboard/analysis'?'rgb(18,139,232)':'rgba(0, 0, 0, 0.65)'}" >首頁</div> </div> <div class="costList1" @click="choiceState('/dashboard/ToExamine')"> <a-badge :count="this.$store.state.applyNum"> <img class="costUrl" v-if="$route.path==='/dashboard/ToExamine'" src="../../assets/img/1.png" /> <img class="costUrl" v-else src="../../assets/img/0.png" /> </a-badge> <div class="costName" :style="{color:$route.path==='/dashboard/ToExamine'?'rgb(18,139,232)':'rgba(0, 0, 0, 0.65)'}" >審核</div> </div> <div class="costList1" @click="choiceState('/dashboard/mine')"> <img class="costUrl" v-if="$route.path==='/dashboard/mine'" src="../../assets/img/mine11.png" /> <img class="costUrl" v-else src="../../assets/img/mine12.png" /> <div class="costName" :style="{color:$route.path==='/dashboard/mine'?'rgb(18,139,232)':'rgba(0, 0, 0, 0.65)'}" >我的</div> </div> </div> </template>
<script> export default { name: 'LayoutFooter', data() { return { applyNum: 0, reimbNum: 0, wgtVer: '' } } methods: { choiceState(path) { this.$router.push(path) } } } </script>
<style lang="scss" scoped> .footer { position: fixed; bottom: 0; width: 100%; display: flex; justify-content: space-between; height: 58px; background: #eff0f6; align-items: center; .costList1 { display: flex; flex-direction: column; justify-content: center; flex: 1; height: 58px; align-items: center; img { width: 20px; height: 22px; } .costName { text-align: center; } } } .ant-carousel >>> .slick-slide { text-align: center; height: 160px !important; line-height: 160px; background: #364d79; overflow: hidden; } .ant-carousel >>> .slick-slide h3 { color: #fff; } </style>
Vue抽取的footer組件,可復用
<template> ? <div class="app-foot"> ? ? {{footerMsgCopyright}} ? ? <span class="source">{{footerMsgName}}</span> ? </div> </template>
<script> export default { ? name: 'AppFoot', ? data() { ? ? return { ? ? ? // 版權說明的文字 ? ? ? footerMsgCopyright: 'Copyright ? 2020-2021 xxxx平臺 - Powered By ', ? ? ? // 單位 ? ? ? footerMsgName: 'xxxx實驗室' ? ? } ? } } </script>
<style scoped> .app-foot { ? /* footer 固定在頁面底部 */ ? min-height: 35px; ? background-color: #eeeeee; ? width: 100%; ? font-size: 14px; ? display: flex; ? align-items: center; ? justify-content: center; } .source{ ? font-weight: 600; } </style>
復用時直接調用組件
主頁面設定高度時,要把footer的高度空出來,其style可以如下:
<style> .main-container{ ? /* ?35 = footer ?*/ ? min-height: calc(100vh - 35px); } </style>
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue 中 beforeRouteEnter 死循環(huán)的問題
這篇文章主要介紹了vue beforeRouteEnter 死循環(huán)的問題,在文章末尾給大家補充介紹了vue中beforeRouteEnter使用的誤區(qū),需要的朋友可以參考下2019-04-04vue中input type=file上傳后@change事件無效的解決方案
這篇文章主要介紹了vue中input type=file上傳后@change事件無效的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05