uniapp 根组建内 获取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
恭喜你 坑可以跳出去了