1. Vue Call Android,ios
-
Vue:
Opencontacts:function () {
Window.nativeObj.openContacts ()
}
-
Android:
Webview.addjavascriptinterface (Contactsinterface, "nativeobj"); The second parameter string is arbitrarily named, referring to the Java entity class in the front JS
- Ios:
Jscontext *jscontext = [Self.mwebview valueforkey:@ "DocumentView.webview.mainFrame.javaScriptContext"];
jscontext[@ "nativeobj"] = self;
2. Android iOS call Vue
-
Vue:
methods:{
Hwajax:function (Strings) {
This.tokenstring=strings;
}
}
Mounted:function () {
Window.hwajax = This.hwajax;
}
-
Android:
Final int version = Build.VERSION.SDK_INT;
Because this method is available in Android version 4.4, version determination is required for use
String url = "Javascript:window." + Hwajax + "()";
if (version < 18) {
Webview.loadurl (URL);
} else {
Webview.evaluatejavascript (URL, new valuecallback<string> () {
@Override
public void Onreceivevalue (String value) {
Here is the result of JS return
}
});
- Ios:
NSString jsstr = @ "Hwajax (' lvkaike ')";
[WebView evaluatejavascript:jsstr completionhandler:^ (id _nullable D, nserror _nullable error) {
}];
Android iOS Vue intermodulation