1、Vue调用android,ios
-
Vue: openContacts:function(){ window.nativeObj.openContacts() }
-
android: Webview.addJavascriptInterface(contactsInterface, "nativeObj"); // 第二个参数 字符串随便命名,代指java的实体类在前面Js
- ios:
JSContext *jsContext = [self.mWebView valueForKey:@"documentView.webview.mainFrame.javaScriptContext"]; jsContext[@"nativeObj"] = self;
2、android ios 调用Vue
-
Vue: methods:{ hwajax:function (strings) { this.tokenString=strings; } } mounted:function () { window.hwajax = this.hwajax; }
-
android: final int version = Build.VERSION.SDK_INT; //因为该方法在 Android 4.4 版本才可使用,所以使用时需进行版本判断 String url = "javascript:window." + hwajax + "()"; if (version < 18) { webView.loadUrl(url); } else { webView.evaluateJavascript(url, new ValueCallback<String>() { @Override public void onReceiveValue(String value) { //此处为 js 返回的结果 } });
- ios:
NSString jsStr = @"hwajax('lvkaike')"; [webView evaluateJavaScript:jsStr completionHandler:^(id _Nullable d, NSError _Nullable error) { }];
|