Tyaco
Tyaco
  • 发布:2021-08-12 14:35
  • 更新:2021-08-12 14:52
  • 阅读:1616

为什么evalJS无效,明明官方就是这样写的

分类:uni-app
                           const self = this;  
            // #ifdef APP-PLUS      
            let currentWebview = getCurrentPages()[0];  
            setTimeout(function() {  
            console.log(self.wv)  
                self.wv = currentWebview.$getAppWebview();  
                //调用下面函数    
                self.handlePostMessage("消息");  
            }, 1000);  
            // #endif    

                    handlePostMessage(res) {  
            console.log(res)  
            this.$refs.webview.evalJS(`handleMessage(${res})`);  
        }
2021-08-12 14:35 负责人:无 分享
已邀请:
jimmy_zejia

jimmy_zejia

var currentWebview = this.$scope.$getAppWebview(); //获取当前页面的webview对象,此对象相当于html5plus里的plus.webview.currentWebview()      
            setTimeout(function() {  
                wv = currentWebview.children()[0];  

                wv.evalJS(`alert(123)`)  
                        }, 300); //如果是页面初始化调用时,需要延时一下 
  • jimmy_zejia

    在export default 外面定义var =wv

    2021-08-12 14:53

  • Tyaco (作者)

    谢谢 非常非常非常非常非常非常有用

    2021-08-13 16:16

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