<template>
<view :style="{paddingTop: statusBarHeight + 'px',background:bg}" class="box">
<view :style="{width: titleBarWidth + 'px', height: titleBarHeight + 'px'}">
<slot name="parent" :menuButtonHeight="menuButtonHeight" :titleBarHeight="titleBarHeight"></slot>
</view>
</view>
</template> <script>
export default {
name: "titleBar",
data() {
return {
statusBarHeight: 0,
menuButtonHeight: 0,
titleBarWidth: 0,
titleBarHeight: 0,
}
},
props: ['bg'],
created() {
this.statusBarHeight = uni.getStorageSync("statusBarHeight");
this.menuButtonHeight = uni.getStorageSync("menuButtonHeight");
this.titleBarWidth = uni.getStorageSync("titleBarWidth");
this.titleBarHeight = uni.getStorageSync("titleBarHeight");
},
onReady() {
uni.setStorageSync('statusBarHeight', uni.getSystemInfoSync().statusBarHeight);
uni.setStorageSync('menuButtonHeight', uni.getMenuButtonBoundingClientRect().height);
uni.setStorageSync('titleBarWidth', uni.getSystemInfoSync().windowWidth - uni.getMenuButtonBoundingClientRect()
.width -
(uni.getSystemInfoSync().windowWidth - uni.getMenuButtonBoundingClientRect().right) * 2);
uni.setStorageSync('titleBarHeight', (uni.getMenuButtonBoundingClientRect().top - uni.getStorageSync(
"statusBarHeight")) * 2 + uni.getStorageSync("menuButtonHeight"));
if (!this.menuButtonHeight) {
this.statusBarHeight = uni.getStorageSync("statusBarHeight");
this.menuButtonHeight = uni.getStorageSync("menuButtonHeight");
this.titleBarWidth = uni.getStorageSync("titleBarWidth");
this.titleBarHeight = uni.getStorageSync("titleBarHeight");
}
}
}
</script> <style>
.box {
position: sticky;
top: 0rpx;
z-index: 999;
}
</style>

效果:

<titleBar bg="#f6f6f6">
<template v-slot:parent>
<view class="xbox">
服务内容
</view>
</template>
</titleBar>
.xbox{
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

微信小程序—标题栏的更多相关文章

  1. 微信小程序教程系列

    微信小程序教程系列 来源:       https://blog.csdn.net/michael_ouyang/article/details/56846185 相关连接:http://blog.c ...

  2. [转]微信小程序之购物车 —— 微信小程序实战商城系列(5)

    本文转自:http://blog.csdn.net/michael_ouyang/article/details/70755892 续上一篇的文章:微信小程序之商品属性分类  —— 微信小程序实战商城 ...

  3. [转]微信小程序之购物数量加减 —— 微信小程序实战商城系列(3)

    本文转自:http://blog.csdn.net/michael_ouyang/article/details/70194144 我们在购买宝贝的时候,购物的数量,经常是我们需要使用的,如下所示: ...

  4. [转]微信小程序之加载更多(分页加载)实例 —— 微信小程序实战系列(2)

    本文转自;http://blog.csdn.net/michael_ouyang/article/details/56846185 loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后 ...

  5. 微信小程序导航:官方工具+精品教程+DEMO集合(1月7更新)

    1:官方工具:https://mp.weixin.qq.com/debug/w ... tml?t=14764346784612:简易教程:https://mp.weixin.qq.com/debug ...

  6. 《微信小程序七日谈》- 第四天:页面路径最多五层?导航可以这么玩

    <微信小程序七日谈>系列文章: 第一天:人生若只如初见: 第二天:你可能要抛弃原来的响应式开发思维: 第三天:玩转Page组件的生命周期: 第四天:页面路径最多五层?导航可以这么玩 微信小 ...

  7. 微信小程序开发常见问题分析

    距离微信小程序内测版发布已经有十几天的时间了,网上对微信小程序的讨论也异常火爆,从发布到现在微信小程序一直占领着各种技术论坛的头条,当然各种平台也对微信小程序有新闻报道,毕竟腾讯在国内影响力还是很大的 ...

  8. 官方问答--微信小程序常见FAQ (17.8.21-17.8.27)

    给提问的开发者的建议:提问之前先查询 文档.通过社区右上角搜索搜索已经存在的问题. 写一个简明扼要的标题,并且正文描述清楚你的问题. 提交 BUG:需要带上基础库版本号,设备信息(iOS, Andro ...

  9. 微信小程序之下拉加载和上拉刷新

    微信小程序下拉加载和上拉刷新两种实现方法 方法一:onPullDownRefresh和onReachBottom方法实现小程序下拉加载和上拉刷新 首先要在json文件里设置window属性       ...

  10. 微信小程序对接串口摄像头

    串口摄像头由树莓派控制,代码如下: # _*_ coding:utf-8 import serial import time import traceback import pycurl import ...

随机推荐

  1. java后端JVM面试资料

    目录 JDK,JRE,JVM三者的区别与联系 讲⼀讲JVM跨平台与跨语⾔ JVM的运⾏时数据区有哪些? 什么是堆内存?堆内存包含哪些部分? 什么是内存溢出 什么是内存泄漏?与内存溢出有什么关系? 对象 ...

  2. Flink Application Development DataStream API Event Time--Flink应用开发DataStream API事件时间

    目录 概览 事件时间 接下来去哪儿 水印生成 水印策略简介 使用水印策略 处理空闲源 写水印生成代码 写周期WatermarkGenerator代码 写符号形式的WatermarkGenerator代 ...

  3. div css 页面中心弹窗窗口

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  4. 更改材质uv

  5. Hystrix-Dashboard可视化

    Hystrix-Dashboard可视化 1.新建子项目引pom.xml <dependencies> <!--hystrix dashboard--> <depende ...

  6. Hook新特性(一)

    基础Hook 1.useState const [state, setState] = useState(initialState); //返回一个state变量,指为initialState,set ...

  7. 关于promise经典面试题

    这里涉及到同步和异步的问题

  8. mybatis查询sql时,在不分页的情况下,自动加了limit导致接口报错

    今天在开发过程中,我遇到了很奇怪的问题.自己写的代码明明没有分页进行查询,但是打印出来的sql缺有limit 导致我getone的时候,出现了二个limit,导致接口报错. ### Cause: or ...

  9. jquery的网络引用地址

    http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min ...

  10. laravel facebook等第三方授权登录

    https://laravelacademy.org/post/9043.html 使用laravel此扩展组件处理 https://developers.facebook.com/apps/?sho ...