uniapp中webview全屏不表现导航栏办理方案

打印 上一主题 下一主题

主题 951|帖子 951|积分 2853

uniapp官网文档地址:https://uniapp.dcloud.net.cn/api/window/window.html#getappwebview

  1. <template>
  2.         <view class="index">
  3.                  <u-navbar :is-back="true" title="标题"" :title-width="650"></u-navbar>
  4.                  <web-view :src="webSrc"></web-view>
  5.          </view>
  6. </template>
  7. <script>
  8. export default {
  9.   name: "index",
  10.   data() {
  11.     return {
  12.       navHeight: 0, // 初始化 navHeight
  13.       webSrc: "",
  14.     };
  15.   },
  16.   onLoad() {
  17.     // #ifdef APP-PLUS
  18.     var that = this;
  19.     var height = 0; // 定义动态的高度变量
  20.     var statusBarHeight = 0;
  21.     uni.getSystemInfo({
  22.       // 成功获取的回调函数,返回值为系统信息
  23.       success: (sysinfo) => {
  24.         that.navHeight = 44; // 假设导航栏高度为 44px,你可以根据实际情况调整
  25.         height =
  26.           sysinfo.windowHeight - that.navHeight - sysinfo.statusBarHeight; // 自行修改,自己需要的高度
  27.         statusBarHeight = sysinfo.statusBarHeight;
  28.       },
  29.       complete: () => {},
  30.     });
  31.     var currentWebview = this.$scope.$getAppWebview(); // 获取当前 web-view
  32.     setTimeout(function () {
  33.       var wv = currentWebview.children()[0];
  34.       wv.setStyle({
  35.         // 设置 web-view 距离顶部的距离以及自己的高度,单位为 px
  36.         top: that.navHeight + statusBarHeight,
  37.         height: height,
  38.       });
  39.     }, 500); // 如页面初始化调用需要写延迟
  40.     // #endif
  41.   }
  42. };
  43. </script>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

雁过留声

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表