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

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.效果图

 

相关文章:

  • 智慧园区综合运营管理平台(SmartPark)和安全EHS平台的分工与协作
  • 金属矫平机:塑造平整与精度的工业利器
  • C++ 引用介绍
  • “域名无法解析”?服务器端DNS故障排查终极指南:从dig/nslookup到系统resolv.conf配置
  • 如何写一份实用的技术文档?——以API接口文档为例
  • 【QT】通讯类HttpAPI:获取MAC、主机IP、端口IP有效性判断
  • 深度解析qemu-guest-agent:架构原理、核心场景与部署实践
  • 【SQL学习笔记2】深入理解 CASE WHEN 的魔法用法
  • 代理服务器选型与性能对比(Nginx vs Pingora vs Envoy vs HAProxy)
  • STL 3算法
  • 在Jenkins上配置邮箱通知
  • 全网首发!AgentCPM-GUI通过adb操控手机教程
  • JAVA语言的学习(Day_1)
  • 【AAOS】【源码分析】用户管理(四)-- 用户切换
  • Day50打卡 @浙大疏锦行
  • Python环境搭建竞赛指南
  • java--怎么定义枚举类
  • 打卡第41天:训练和测试的规范写法
  • 2005-2021年中国地下水位年鉴数据(EXCEL/PDF)包含:各省监测点、监测深度等
  • 深度学习聊天机器人 需要考虑
  • win10 电脑做网站服务器吗/百度推广平台登录入口
  • 苏州网站制作方法/沧州网络推广外包公司
  • 昌邑网站建设公司/百度如何搜索网址
  • 上海品牌网站开发/天津网络优化推广公司
  • 福田做商城网站建设多少钱/自己创建网站
  • 北京高端网站建设飞沐/国内新闻最近新闻今天