vue调取不到原生android的方法

最近在用vue写商城H5,打算嵌入到原生app中,但是在调用原生android方法时,却发现调不到android提供的方法
这是我调用原生app的方法

代码在html页面中 android是好用的,请问一下vue中调原生方法和html中有什么不同吗?

求谁能帮我看看原因

vue下的方法

callPhone(){
  let params = {
        photoUrl: "http://img.minweixian.com/webfile/purchase/qrcode_test.jpg",
        title:"测试"
    };
       if (/android/i.test(navigator.userAgent)) {
        // try {
        
          state.Toast.fail("我是安卓"+!window["android"]) //找不到window["android"]
          window.android.orderPhotoxz(params.photoUrl,params.title);
       
      } else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
        try {
          window.webkit.messageHandlers.tel.postMessage(params);
        } catch (e) {
          console.log(e);
        }
      }
}

html下的方法

 function save() {
        var params = {
        photoUrl: "http://img.minweixian.com/webfile/purchase/qrcode_test.jpg",
        title:"测试"
    };
    
        if (/android/i.test(navigator.userAgent)) {
            
            try {
                alert(params.photoUrl+";"+params.title);
                window.android.orderPhotoxz(params.photoUrl,params.title);
            } catch (e) {
                console.log(e);
            }
        } else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
            try {
                window.webkit.messageHandlers.orderPhotoxz.postMessage(params);
            } catch (e) {
                console.log(e);
            }
        }
    }
阅读 1.8k
1 个回答

加个延时试试

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题