onShow() {
// #ifdef APP-PLUS
setTimeout(()=> {
let that = this;
let height = 0; //定义动态的高度变量,如高度为定值,可以直接写
let statusBarHeight = 0;
uni.getSystemInfo({
//成功获取的回调函数,返回值为系统信息
success: (sysinfo:any) => {
height = sysinfo.windowHeight - that.actionBarHeight - sysinfo.statusBarHeight; //自行修改,自己需要的高度
statusBarHeight = sysinfo.statusBarHeight;
},
complete: () => {}
});
// var currentWebview = this.$mp.page.$getAppWebview();
// var currentWebview = this.$parent.$scope.$getAppWebview()
let scopWeb = this.$scope; //获取当前web-view
console.log("==== ",scopWeb)
let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
let wv = currentWebview.children()[0];
wv.setStyle({ //设置web-view距离顶部的距离以及自己的高度,单位为px
top: statusBarHeight+that.actionBarHeight,
height: height
})
}, 500); //如页面初始化调用需要写延迟
// #endif
}
- 发布:2021-03-24 10:51
- 更新:2021-03-24 10:53
- 阅读:597
产品分类: uniapp/App
PC开发环境操作系统: Mac
PC开发环境操作系统版本号: 14.4
HBuilderX类型: 正式
HBuilderX版本号: 3.1.6
手机系统: Android
手机系统版本号: Android 10
手机厂商: 华为
手机机型: 华为mate30
页面类型: vue
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
[HBuilder] 10:47:23.471 ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
[HBuilder] 10:47:23.471 ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
预期结果:
[HBuilder] 10:47:23.471 ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
[HBuilder] 10:47:23.471 ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
实际结果:
[HBuilder] 10:47:23.471 ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
[HBuilder] 10:47:23.471 ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
bug描述:
打包问题
现象:编译成功,可在手机运行并且设置有效,打包失败。
日志:
ERROR in /Users/Shared/iosworkplace/build-science-center/src/pages/ShowWeb.vue(73,24):
[HBuilder] 10:47:23.472 73:24 Property '$scope' does not exist on type 'ShowWeb'.
[HBuilder] 10:47:23.489 71 | // var currentWebview = this.$mp.page.$getAppWebview();
[HBuilder] 10:47:23.490 72 | // var currentWebview = this.$parent.$scope.$getAppWebview()
[HBuilder] 10:47:23.503 > 73 | let scopWeb = this.$scope; //获取当前web-view
[HBuilder] 10:47:23.503 | ^
[HBuilder] 10:47:23.508 74 | console.log("==== ",scopWeb)
[HBuilder] 10:47:23.509 75 | let currentWebview:any = this.$scope.$getAppWebview(); //获取当前web-view
[HBuilder] 10:47:23.514 76 | let wv = currentWebview.children()[0];
可以看到 $scope不存在,该怎么解决?最新版XH
预期:修改webview高度。
1 个回复
d***@foxmail.com (作者) - CASD
这里是源码(TS)