3***@qq.com
3***@qq.com
  • 发布:2020-05-15 15:08
  • 更新:2021-05-12 16:33
  • 阅读:2452

uniapp 获取webview对象报错

分类:uni-app

官方文档:
<template>
<view>
<web-view src="https://www.baidu.com"></web-view>
</view>
</template>
<script>
var wv;//计划创建的webview
export default {
onReady() {
// #ifdef APP-PLUS
var currentWebview = this.$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:150,height:300})
}, 1000); //如果是页面初始化调用时,需要延时一下
// #endif
}
};
</script>

我加载 var currentWebview = this.$scope.$getAppWebview()就会报错。

"Cannot read property '$getAppWebview' of undefined"

2020-05-15 15:08 负责人:无 分享
已邀请:
f***@163.com

f***@163.com

你好,有解决方案吗?我也遇到这个问题
有些帖子说this.$parent.$scope.$getAppWebview,我试了也是无效

3***@qq.com

3***@qq.com (作者) - 小学生

快来人呐。

  • 5***@qq.com

    请问解决吗?我这边同样的报错

    2020-07-27 11:33

a***@gmail.com

a***@gmail.com

我是能获取到
console.log("currentWebview:", currentWebview) 有获取到 ,有值
console.log(currentWebview.getURL())
console.log(currentWebview.back())

10:58:20.708 currentWebview:, [Object] {"__view_array":[],"IDENTITY":"NWindow","uuid":"NWindow151597373452303","callbacks__":{"pullTo...} at pages/2game/game.nvue:41

10:58:20.739 file:///storage/emulated/0/Android/data/com.shangrao.hacienda/apps/UNIE519D66/www/pages/2game/game.js at pages/2game/game.nvue:42 // getURL() 获取 url 地址 位 js 路径 什么鬼

10:58:20.771 undefined at pages/2game/game.nvue:43 //back() 返回无法使用

该问题目前已经被锁定, 无法添加新回复