uni-app $scope找不到
uni-app $scope找不到
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Mac | 14.4 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Mac
PC开发环境操作系统版本号:14.4
HBuilderX类型:正式
HBuilderX版本号:3.1.6
手机系统:Android
手机系统版本号:Android 10
手机厂商:华为
手机机型:华为mate30
页面类型:vue
打包方式:云端
项目创建方式:HBuilderX
示例代码:
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 }
操作步骤:
[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];
更多关于uni-app $scope找不到的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这里是源码(TS)
<template>
<view class="bim_body">
<u-navbar :title="newsTitle" title-color="#fff" back-icon-color="#ffffff" :background="{
'background-color': '#010B14'}"
back-icon-name="arrow-left" :custom-back="onClickContract" back-icon-size="32">
<view class="navbar-right" slot="right">
<view class=“dot-box right-item” @click=“onClickShare”>
<u-icon name="share-fill" size="32"></u-icon>
</view>
</view>
</u-navbar>
<web-view v-if="bimUrl" :src="bimUrl" :webview-styles="webviewStyles"></web-view>
</view>
</template>
更多关于uni-app $scope找不到的实战教程也可以访问 https://www.itying.com/category-93-b0.html


