uniapp 获取getAppWebview()对象报错 undefined
uniapp每日踩坑,建议跑路
言归正传,最近使用到webview做地图嵌入到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()无效
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”
先贴网上给的解决方案:
使用这个替换
var currentWebview = this.$parent.$scope.$getAppWebview()
但我的还是报错,猛男落泪
后面看到一个好心人说是h5和app的差异,突然想到是不是只能用于app端,然后鬼使神差的加了
// #ifdef APP-PLUS
// #endif
发现就可以了,是我自己拉了,抄都没抄完整