当前位置: 首页 > web >正文

uniapp自定义导航栏,采用粘性定位

1.使用自定义状态栏,在pages.json中设置

{"path": "pages/index/index","style": {"navigationStyle": "custom" //自定义导航栏}},

2.在app.vue中获取胶囊信息

<script setup lang="ts">import { useSystemStore } from "@/store/index";const systemStore = useSystemStore();import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";onLaunch(() => {let obj = uni.getMenuButtonBoundingClientRect()let { top, bottom, height } = objsystemStore.setMenuButtonBounding({ top, bottom, height })});onShow(() => {console.log("App Show");});onHide(() => {console.log("App Hide");});
</script>
<style lang="scss">/*每个页面公共css */page, .page-content{width: 100%;height: 100%;}@import "uview-plus/index.scss";
</style>

3.封装defaultNavbar.vue组件

<template><view class="page-content"><view class="pageTitle" :style="{ 'height': `${menuButtonBounding.bottom + 5}px`, 'position': 'relative' }"><view class="titleText":style="{ 'height': `${menuButtonBounding.height}px`, 'line-height': `${menuButtonBounding.height}px`, 'bottom': '5px', 'position': 'absolute', 'text-align': 'center' }"><view class="backIcon" @click="linkToBack"><i class="iconfont icon-fanhui zlcIcon"></i></view><view class="text">{{ props.pageTitle }}</view><view class="menuButton"></view></view></view></view>
</template><script setup lang="ts">import { defineProps } from "vue"import { useSystemStore } from "@/store/index";const systemStore = useSystemStore();//胶囊信息let { menuButtonBounding } = systemStoreinterface Props {pageTitle : string}//传递的页面标题const props = withDefaults(defineProps<Props>(), {pageTitle: '页面标题'})//返回上一页let linkToBack = () : void => {uni.navigateBack()}
</script><style lang="scss" scoped>@import url('@/iconfont/iconfont.css');.page-content {position: -webkit-sticky; /* Safari需要前缀 */position: sticky;z-index: 99;width: 100vw;height: fit-content;top: 0;background: linear-gradient(to bottom right, rgba(255, 252, 253, 1), rgba(255, 231, 237, 1), rgba(254, 252, 252, 1));.pageTitle {border-bottom: 1px solid #f8f2ff;.titleText {width: 100%;white-space: nowrap;display: flex;flex-direction: row;align-items: center;justify-content: space-between;padding: 0 20rpx;box-sizing: border-box;text-align: center;font-weight: bold;.backIcon {font-size: 30rpx;width: 40rpx;text-align: center;color: rgba(36, 37, 83, 1);}.text {color: rgba(36, 38, 81, 1);}.menuButton {width: 40rpx;}}}}
</style>

4.在页面中使用

 5.效果图

 

http://www.xdnf.cn/news/13385.html

相关文章:

  • STM32 PID控制
  • python打卡训练营打卡记录day50
  • 林清轩以研发为核,用专利技术筑就高端国货护肤壁垒
  • 函数02 day11
  • AI赋能农业
  • 第十六章 I2C
  • 【PhysUnits】17.6 Unit基础结构(unit.rs)
  • <component :is=““>
  • CentOS7下的ZooKeeper部署
  • 55. Jump Game
  • Redis持久化策略介绍,以及如何选择?
  • 第二十四章 通用同步异步收发器(USART)
  • java异步编程难题拆解
  • Java 中 switch-case 语句的执行逻辑与避坑指南
  • Java判断规则工具类
  • 工作日记总结-transaction is aborted, commands ignored until end of transaction block
  • [软件测试]:什么是自动化测试?selenium+webdriver-manager的安装,实现你的第一个脚本
  • Kotlin基础语法二
  • 大数据学习(136)-数据埋点
  • 玄机 日志分析-Tomcat日志分析 WriteUp
  • G-Star公益行 | 公益组织入门开源技术,六月北京点燃改变的星火
  • 【MySQL数据库】InnoDB存储引擎:事务原理redolog、undolog与版本控制MVCC
  • QuecPython 文件系统操作
  • 多光谱图像技术在苗期作物与杂草识别中的研究进展
  • C语言学习20250610
  • Dynadot邮箱工具指南(六):将域名邮箱添加至网易邮箱大师
  • Leetcode 3576. Transform Array to All Equal Elements
  • 新能源知识库(34)什么是单一制和两部制
  • 【SAP MM SD FICO】销售视图和会计视图
  • C++ 8.1内联函数之宏定义