uniapp实战 —— 自定义顶部导航栏

效果预览

下图中的红框区域

在这里插入图片描述

范例代码

src\pages.json

配置隐藏默认顶部导航栏

     "navigationStyle": "custom", // 隐藏默认顶部导航

在这里插入图片描述

src\pages\index\components\CustomNavbar.vue

封装自定义顶部导航栏的组件(要点在于:获取屏幕边界到安全区域距离)

<script setup lang="ts">
// 获取屏幕边界到安全区域距离
const {
      safeAreaInsets } = uni.getSystemInfoSync()
</script>

<template>
  <view class="navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
    <view class="logo">
      <!-- <image class="logo-image" src="@/static/images/logo.jpg"></image> -->
      <text class="logo-title">DOS圆梦大家庭</text>
      <text class="logo-text">诚挚缘分 成就梦想</text>
    </view>
  </view>
</template>

<style lang="scss">
.navbar {
     
  background-image: url(@/static/images/navigator_bg.png);
  background-size: cover;
  display: flex;
  .logo {
     
    display: flex;
    align-items: center;
    height: 86rpx;
    padding: 20rpx;
    .logo-image {
     
      width: 40rpx;
      height: 40rpx;
    }
    .logo-title {
     
      font-size: 32rpx;
      color: #fff;
      font-weight: bold;
    }
    .logo-text {
     
      flex: 1;
      line-height: 28rpx;
      color: #fff;
      margin: 2rpx 0 0 20rpx;
      padding-left: 20rpx;
      border-left: 1rpx solid #fff;
      font-size: 26rpx;
    }
  }
}
</style>

src\pages\index\index.vue

在目标页面中导入使用

import CustomNavbar from './components/CustomNavbar.vue'
<CustomNavbar />

相关推荐

  1. Uniapp定义导航

    2023-12-11 10:52:02       57 阅读
  2. uniapp——定义导航的封装

    2023-12-11 10:52:02       61 阅读
  3. Uniapp导航右侧定义图标文字按钮

    2023-12-11 10:52:02       27 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-11 10:52:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-11 10:52:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-11 10:52:02       82 阅读
  4. Python语言-面向对象

    2023-12-11 10:52:02       91 阅读

热门阅读

  1. 【打卡】牛客网:BM61 矩阵最长递增路径

    2023-12-11 10:52:02       60 阅读
  2. 线材连接器

    2023-12-11 10:52:02       54 阅读
  3. 快速幂 FastPower

    2023-12-11 10:52:02       64 阅读
  4. Git安装

    Git安装

    2023-12-11 10:52:02      57 阅读
  5. 海外独立站站长常用的ChatGPT通用提示词模板

    2023-12-11 10:52:02       67 阅读
  6. SQL命令---删除数据表

    2023-12-11 10:52:02       53 阅读