rebelll
rebelll
  • 发布:2023-03-03 15:05
  • 更新:2023-03-04 11:48
  • 阅读:495

请问webview实例获取时机,无法精准控制webview获取时机

分类:uni-app
const createWV = () => {  
  const pages = getCurrentPages();  
  const page = pages[pages.length - 1];  
  const currentWebview = page.$getAppWebview();  
  wv = currentWebview.children()[0];  
  wv.setStyle({  
    top: ' 0',  
    background: 'transparent',  
  });  
  console.log('触发');  
};  

onMounted(() => {  
  setTimeout(() => {  
    createWV();  
  }, 300);  
});

必须在onMounted钩子setTimeout获取才能获取,但是太不可控了

有其他方法吗 IOS vue3

2023-03-03 15:05 负责人:无 分享
已邀请:
BoredApe

BoredApe - 有问题就会有答案。

webviewuni-app的双向通信可以使用以下方式:

webview/h5 发送消息:

plus.webview.postMessageToUniNView({  
 type: 'toUniAPP',  
 args: {  
     arg1: '123'  
 }  
}, '__uniapp__service');

uni-app 接受消息:

plus.globalEvent.addEventListener('plusMessage', (message)=>{  
// message打印的结果:  
// {  
//     "data": {  
//         "type": "toUniAPP",  
//         "args": {  
//             "arg1": "123"  
//         }  
//     },  
//     "targetId": "__uniapp__service",  
//     "originId": "NWindow101677899611098"  
// }  
})
  • 哇哦uni

    plus 在h5 中好像用不了耶

    2023-03-22 14:41

  • BoredApe

    回复 哇哦uni: h5的宿主环境需要是uni-app打包的APP。或者集成了uniSDK的APP。

    2023-03-22 14:44

  • 哇哦uni

    回复 BoredApe: 我就是uniapp 打包的ios 自定义基座应该可以吧

    2023-03-22 14:45

  • 哇哦uni

    我h5也是uniapp app 也是uniapp开发的

    2023-03-22 14:45

  • BoredApe

    回复 哇哦uni: 可以的

    2023-03-22 14:47

  • 哇哦uni

    回复 BoredApe: 我使用 plus.webview.create 创建的webview h5 就没法执行plus 根本找不到

    2023-03-22 14:56

  • wjwj

    回复 哇哦uni: create里参数: plusrequire:"none", //禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止

    被你关闭了吧

    2023-09-06 17:18

BoredApe

BoredApe - 有问题就会有答案。

  • rebelll (作者)

    主要是我们业务需要植入腾讯云验证码 SDK 只能通过webview加载,这边可控了,腾讯云那边就不可控了

    2023-03-03 15:17

  • BoredApe

    回复 rebelll: 就是通过webview加载。web-view组件不也是通过url打开连接吗

    2023-03-03 15:21

  • rebelll (作者)

    回复 BoredApe: 好的我明白你意思了,我试试

    2023-03-03 15:23

  • rebelll (作者)

    回复 BoredApe: 但是这样就没有办法双向通信了把,腾讯云验证完了发送标识,App端也无法接受了呀

    2023-03-03 15:29

要回复问题请先登录注册