<template>
<view class="index">
<u-navbar :is-back="true" title="标题"" :title-width="650"></u-navbar>
<web-view :src="webSrc"></web-view>
</view>
</template>
<script>
export default {
name: "index",
data() {
return {
navHeight: 0, // 初始化 navHeight
webSrc: "",
};
},
onLoad() {
// #ifdef APP-PLUS
var that = this;
var height = 0; // 定义动态的高度变量
var statusBarHeight = 0;
uni.getSystemInfo({
// 成功获取的回调函数,返回值为系统信息
success: (sysinfo) => {
that.navHeight = 44; // 假设导航栏高度为 44px,你可以根据实际情况调整
height =
sysinfo.windowHeight - that.navHeight - sysinfo.statusBarHeight; // 自行修改,自己需要的高度
statusBarHeight = sysinfo.statusBarHeight;
},
complete: () => {},
});
var currentWebview = this.$scope.$getAppWebview(); // 获取当前 web-view
setTimeout(function () {
var wv = currentWebview.children()[0];
wv.setStyle({
// 设置 web-view 距离顶部的距离以及自己的高度,单位为 px
top: that.navHeight + statusBarHeight,
height: height,
});
}, 500); // 如页面初始化调用需要写延迟
// #endif
}
};
</script>