//前端
iPhone:function(strings) {
alert('你好');
}
//安卓
mWebview.evaluateJavascript("javascript:iPhone("+resCode+")", new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
//此处为 js 返回的结果
}
});
//ios
[self.webView evaluateJavaScript:[NSString stringWithFormat:@"iPhone(resCode)"] completionHandler:^(id _Nullable item, NSError * _Nullable error) {
NSLog(@"error:%@",error);
}];
前端是用vue2.0写的,vue中需要将方法挂载到全局中,正确的前端写法是在mounted方法里面加上window.iPhone= this.iPhone,
mounted() {
window.iPhone= this.iPhone
},
methods: {
iPhone(strings) {
alert('你好');
}
}