uniapp app内this.$scope.$getAppWebview() 报错Cannot read property ‘$getAppWebview‘ of undefined

uniapp  根组建内  v3引擎 获取webview  使用代码

// #ifdef APP-PLUS
		var currentWebview = this.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
		console.info(currentWebview)
		setTimeout(function() {
				  wv = currentWebview.children()[0]
				  wv.setStyle({top:-0,height:0})
		}, 1000); //如果是页面初始化调用时,需要延时一下
		// #endif  

但是 到了 组建内 使用这个方法 报错    undefined  四处搜寻   终于找到解决办法

使用

var currentWebview = this.$parent.$scope.$getAppWebview()

就好使了  特此记录一下

补充==============================================>

如果你搜到的上面的问题 那你我可定有缘  我补充另一个坑

我的代码要动态改变app内webview的高度  由于 我是只想引入网络上的js  所以 我引入了一个webveiw 然后 动态 把高度设置成0 然后 利用这个webview去加载 我的js  然后 app和h5 进行交互 调用 我想用的网路js的代码

// #ifdef APP-PLUS
	  var currentWebview = this.$parent.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
	  setTimeout(function() {
	  		  wv = currentWebview.children()[0]
	  		  wv.setStyle({top:-0,height:0})
	  }, 60); //如果是页面初始化调用时,需要延时一下
	  // #endif

上面这版 在ios里 完美好用   尽管页面 会 闪烁一下 因为webview默认是全屏的    不过 这里可以当作加载过程  可以放一个进度条 不影响业务

但是注意:

当放到  安卓里的时候  问题出现了, Android里  是无法动态将高度设置成0的!!!!!!!!

所以 最后的代码

// #ifdef APP-PLUS
	  var currentWebview = this.$parent.$scope.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效,非v3编译模式使用this.$mp.page.$getAppWebview()
	  setTimeout(function() {
	  		  wv = currentWebview.children()[0]
	  		  wv.setStyle({top:-100,height:1})
	  }, 60); //如果是页面初始化调用时,需要延时一下
	  // #endif

恭喜你  坑可以跳出去了

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值