uniapp官网文档地址:https://uniapp.dcloud.net.cn/api/window/window.html#getappwebview
- <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>
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |