小程序
小游戏
企业微信
微信支付
扫描小程序码分享
- 当前 Bug 的表现(可附上截图)
- 预期表现
- 复现路径
- 提供一个最简复现 Demo
mpvue框架,自定义头部,使用cover-view写在头部,使用position:fixed,样式。在PC调试没问题,真机头部会随着页面拖动而移动,fixed失效。
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
已经解决了,这个fixed样式的cover-view同级我还有一个占位的cover-view,用来保证高度的,同时外层包了一层无样式的cover-view,导致fixed样式失效。就是只能最外层的cover-view只能是fixed的属性,fixed才会生效,如果fixed外层再包一层无样式的cover-view就会导致该问题。
不知道是不是算是渲染的bug,还是太严谨了。给你看下两次的代码。一个组件,
这是原版的,fixed失效。
<template>
<cover-view class="comp-navbar">
<!-- 占位栏 -->
<cover-view class="placeholder-bar" :style="{height: navBarHeight + 'px'}"> </cover-view>
<!-- 导航栏主体 -->
<cover-view class="navbar" :style="{height: navBarHeight + 'px',backgroundColor:navBackgroundColor}">
<!-- 状态栏 -->
<cover-view class="nav-statusbar" :style="{height: statusBarHeight + 'px'}"></cover-view>
<!-- 标题栏 -->
<cover-view class="nav-titlebar" :style="{height: titleBarHeight + 'px' }">
<!-- home及后退键 -->
<cover-view class="bar-options" v-if="!isHome">
<cover-view v-if="backVisible" class="opt opt-back" @click="backClick()">
<!--<span class="iconfont icon-fanhui"></span>-->
<cover-image src="./../../static/img/backNav.png"></cover-image>
</cover-view>
<cover-view class="line" v-if="backVisible && homePath"></cover-view>
<cover-view v-if="homePath" class="opt opt-home" @click="homeClick()">
<!--<span class="iconfontHome icon-shouye"></span>-->
<cover-image src="./../../static/img/home.png"></cover-image>
<!-- 标题 -->
<cover-view class="bar-title" :style="[{color:titleColor}]">{{title}}</cover-view>
</template>
<script>
import {mapGetters} from 'vuex'
export default {
props: {
// 导航栏背景色
navBackgroundColor: {
type:String,
default: "#ffffff"
},
// 标题颜色
titleColor: {
default: "#000000"
//标题文字
title: {
required: false,
default: "来画大世界"
// 是否显示后退按钮
backVisible: {
default: false
// home按钮的路径
homePath: {
default: ""
pageUrl: {
type: String,
default:''
}
data() {
return {
theme_skin_color: this.$store.state.user.theme_skin_color,
statusBarHeight: "", // 状态栏高度
titleBarHeight: "", // 标题栏高度
navBarHeight: "", // 导航栏总高度
platform: "",
model: "",
brand: "",
system: "",
};
computed: {
beforeMount() {
const self = this;
wx.getSystemInfo({
success(system) {
self.statusBarHeight = system.statusBarHeight;
self.platform = system.platform;
self.model = system.model;
self.brand = system.brand;
self.system = system.system;
let platformReg = /ios/i;
if (platformReg.test(system.platform)) {
self.titleBarHeight = 44;
} else {
self.titleBarHeight = 48;
self.navBarHeight = self.statusBarHeight + self.titleBarHeight;
let width = system.windowWidth;
self.$store.commit('SET_NAV_HEIGHT',self.navBarHeight)
self.$store.commit('SET_RATE',width/750)
});
mounted() {},
methods: {
</script>
<style lang="scss" scoped>
@import "../../assets/iconfont/iconfont.css";
.comp-navbar {
width: 100%;
.navbar {
position: fixed !important;
left: 0;
top: 0;
z-index:9999;
.nav-titlebar {
// border: 1px solid green;
display: flex;
align-items: center;
justify-content: center;
position: relative;
.bar-options {
// width: 87px;
// height: 30px;
width: 170rpx;
height: 60rpx;
// border: 1px solid hsla(0, 0%, 100%, .25);
// border: 1px solid #ededed;
box-sizing: border-box;
justify-content: space-around;
position: absolute;
left: 7px;
background: hsla(0, 0%, 100%, 0.6);
border-radius: 27px;
padding-right: 5rpx;
.opt {
width: 50rpx;
height: 50rpx;
.opt-back {
cover-image {
width:38rpx;
height:36rpx;
.line {
display: block;
height: 30rpx;
width: 1px;
background-color: #bfbfbf;
.opt-home {
.bar-title {
width: 45%;
font-size: 0.38rem;
font-weight: bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: center;
.placeholder-bar{
background-color: transparent;
</style>
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
已经解决了,这个fixed样式的cover-view同级我还有一个占位的cover-view,用来保证高度的,同时外层包了一层无样式的cover-view,导致fixed样式失效。就是只能最外层的cover-view只能是fixed的属性,fixed才会生效,如果fixed外层再包一层无样式的cover-view就会导致该问题。
不知道是不是算是渲染的bug,还是太严谨了。给你看下两次的代码。一个组件,
这是原版的,fixed失效。
<template>
<cover-view class="comp-navbar">
<!-- 占位栏 -->
<cover-view class="placeholder-bar" :style="{height: navBarHeight + 'px'}"> </cover-view>
<!-- 导航栏主体 -->
<cover-view class="navbar" :style="{height: navBarHeight + 'px',backgroundColor:navBackgroundColor}">
<!-- 状态栏 -->
<cover-view class="nav-statusbar" :style="{height: statusBarHeight + 'px'}"></cover-view>
<!-- 标题栏 -->
<cover-view class="nav-titlebar" :style="{height: titleBarHeight + 'px' }">
<!-- home及后退键 -->
<cover-view class="bar-options" v-if="!isHome">
<cover-view v-if="backVisible" class="opt opt-back" @click="backClick()">
<!--<span class="iconfont icon-fanhui"></span>-->
<cover-image src="./../../static/img/backNav.png"></cover-image>
</cover-view>
<cover-view class="line" v-if="backVisible && homePath"></cover-view>
<cover-view v-if="homePath" class="opt opt-home" @click="homeClick()">
<!--<span class="iconfontHome icon-shouye"></span>-->
<cover-image src="./../../static/img/home.png"></cover-image>
</cover-view>
</cover-view>
<!-- 标题 -->
<cover-view class="bar-title" :style="[{color:titleColor}]">{{title}}</cover-view>
</cover-view>
</cover-view>
</cover-view>
</template>
<script>
import {mapGetters} from 'vuex'
export default {
props: {
// 导航栏背景色
navBackgroundColor: {
type:String,
default: "#ffffff"
},
// 标题颜色
titleColor: {
default: "#000000"
},
//标题文字
title: {
required: false,
default: "来画大世界"
},
// 是否显示后退按钮
backVisible: {
required: false,
default: false
},
// home按钮的路径
homePath: {
required: false,
default: ""
},
pageUrl: {
type: String,
default:''
}
},
data() {
return {
theme_skin_color: this.$store.state.user.theme_skin_color,
statusBarHeight: "", // 状态栏高度
titleBarHeight: "", // 标题栏高度
navBarHeight: "", // 导航栏总高度
platform: "",
model: "",
brand: "",
system: "",
};
},
computed: {
},
beforeMount() {
const self = this;
wx.getSystemInfo({
success(system) {
self.statusBarHeight = system.statusBarHeight;
self.platform = system.platform;
self.model = system.model;
self.brand = system.brand;
self.system = system.system;
let platformReg = /ios/i;
if (platformReg.test(system.platform)) {
self.titleBarHeight = 44;
} else {
self.titleBarHeight = 48;
}
self.navBarHeight = self.statusBarHeight + self.titleBarHeight;
let width = system.windowWidth;
self.$store.commit('SET_NAV_HEIGHT',self.navBarHeight)
self.$store.commit('SET_RATE',width/750)
}
});
},
mounted() {},
methods: {
}
};
</script>
<style lang="scss" scoped>
@import "../../assets/iconfont/iconfont.css";
.comp-navbar {
width: 100%;
.navbar {
position: fixed !important;
left: 0;
top: 0;
width: 100%;
z-index:9999;
.nav-titlebar {
// border: 1px solid green;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
.bar-options {
// width: 87px;
// height: 30px;
width: 170rpx;
height: 60rpx;
display: flex;
// border: 1px solid hsla(0, 0%, 100%, .25);
// border: 1px solid #ededed;
box-sizing: border-box;
align-items: center;
justify-content: space-around;
position: absolute;
left: 7px;
display: flex;
align-items: center;
background: hsla(0, 0%, 100%, 0.6);
border-radius: 27px;
padding-right: 5rpx;
.opt {
width: 50rpx;
height: 50rpx;
display: flex;
justify-content: center;
align-items: center;
}
.opt-back {
cover-image {
width:38rpx;
height:36rpx;
}
}
.line {
display: block;
height: 30rpx;
width: 1px;
background-color: #bfbfbf;
}
.opt-home {
cover-image {
width:38rpx;
height:36rpx;
}
}
}
.bar-title {
width: 45%;
font-size: 0.38rem;
font-weight: bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: center;
}
}
}
.placeholder-bar{
background-color: transparent;
width: 100%;
}
}
</style>