微信小程序—标题栏
<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;
}
微信小程序—标题栏的更多相关文章
- 微信小程序教程系列
微信小程序教程系列 来源: https://blog.csdn.net/michael_ouyang/article/details/56846185 相关连接:http://blog.c ...
- [转]微信小程序之购物车 —— 微信小程序实战商城系列(5)
本文转自:http://blog.csdn.net/michael_ouyang/article/details/70755892 续上一篇的文章:微信小程序之商品属性分类 —— 微信小程序实战商城 ...
- [转]微信小程序之购物数量加减 —— 微信小程序实战商城系列(3)
本文转自:http://blog.csdn.net/michael_ouyang/article/details/70194144 我们在购买宝贝的时候,购物的数量,经常是我们需要使用的,如下所示: ...
- [转]微信小程序之加载更多(分页加载)实例 —— 微信小程序实战系列(2)
本文转自;http://blog.csdn.net/michael_ouyang/article/details/56846185 loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后 ...
- 微信小程序导航:官方工具+精品教程+DEMO集合(1月7更新)
1:官方工具:https://mp.weixin.qq.com/debug/w ... tml?t=14764346784612:简易教程:https://mp.weixin.qq.com/debug ...
- 《微信小程序七日谈》- 第四天:页面路径最多五层?导航可以这么玩
<微信小程序七日谈>系列文章: 第一天:人生若只如初见: 第二天:你可能要抛弃原来的响应式开发思维: 第三天:玩转Page组件的生命周期: 第四天:页面路径最多五层?导航可以这么玩 微信小 ...
- 微信小程序开发常见问题分析
距离微信小程序内测版发布已经有十几天的时间了,网上对微信小程序的讨论也异常火爆,从发布到现在微信小程序一直占领着各种技术论坛的头条,当然各种平台也对微信小程序有新闻报道,毕竟腾讯在国内影响力还是很大的 ...
- 官方问答--微信小程序常见FAQ (17.8.21-17.8.27)
给提问的开发者的建议:提问之前先查询 文档.通过社区右上角搜索搜索已经存在的问题. 写一个简明扼要的标题,并且正文描述清楚你的问题. 提交 BUG:需要带上基础库版本号,设备信息(iOS, Andro ...
- 微信小程序之下拉加载和上拉刷新
微信小程序下拉加载和上拉刷新两种实现方法 方法一:onPullDownRefresh和onReachBottom方法实现小程序下拉加载和上拉刷新 首先要在json文件里设置window属性 ...
- 微信小程序对接串口摄像头
串口摄像头由树莓派控制,代码如下: # _*_ coding:utf-8 import serial import time import traceback import pycurl import ...
随机推荐
- xd p4 WEB源码拓展
WEB 源码在安全测试中是非常重要的信息来源,可以用来代码审计漏洞也可以用来做信息突破口,其中 WEB 源码有很多技术需要简明分析. 知识点 关于 WEB 源码目录结构 后台目录.模板目录.数据库目录 ...
- ObjectARX2016-2创建直线
众所周知,数据库里面包含各种数据表,而数据表里面又是各种记录,当然还有字段.AUTOCAD里面对于图形的管理也是基于图形数据库的.因此,想要在DWG里面添加一条直线,只需要做三件事: (1)打开数据表 ...
- 从create-react-app 学点东西1:web-vitals
导言 市场中流行的框架有很多地方是值得我们深入的去探究或学习的,<从create-react-app学点东西>这系列文章从create-react-app创建的项目中找出一些重要或者容易忽 ...
- CSS3选择器nth-child(n)
CSS3选择器nth-child(n)实现隔几行选择元素 nth-child(n),n 可以是数字.关键词或公式.选择器匹配属于其父元素的第N个子元素,不论元素的类型. 序号写法:li:nth-chi ...
- nacos原理
配置中心原理 1.Nacos 客户端使用长轮询请求客户端变更数据,并且设置30s超时,当配置发生变化响应会立即返回,否则一直等到29.5s之后再返回响应. 2.客户端的请求到达服务端后,服务端将该请求 ...
- IPC,进程间通信
信号机制 也叫软中断,软件层次上对中断的模拟 kill -9 加进程号可以终止进程 linux下执行kill -l可以看到 这里面居然没有32 33 直接从31到34 所以一共是62个信号 1) SI ...
- (四)REDIS-布隆过滤器及缓存
(一)布隆过滤器 布隆过滤器(英语,Bloom Filter)是1970年由布隆提出的.它实际是一个很长的二进制数组+多个随机Hash算法映射函数,主要用于判断一个元素是否在集合中. 通常我们会遇到很 ...
- Python学习笔记调试之取得反向跟踪的字符串
随笔记录方便自己和同路人查阅. #------------------------------------------------我是可耻的分割线--------------------------- ...
- 把VScode插件提示abc的提示给移到最后
把VScode插件提示abc的提示给移到最后 解决方法 打开设置,在搜索中输入editor.snippetSuggestions,然后将选项改为top,就可以解决了 top:就是将你插件提示放到最上面 ...
- .net基础—多线程(二)
Thread 在.NET中最早提供的控制线程类型的类型:System.Threading.Thread类.使用该类型可以直观地创建.控制和结束线程.下面是一个简单的多线程程序: static void ...