native-jsbridge
v1.0.6-1
Published
js plugin for between H5 and Native
Downloads
4
Maintainers
Readme
native-jsbridge
用于H5和native之间通信的JS插件,支持Typescript
Native需要集成的配套插件
- IOS(UIWebview): https://github.com/marcuswestin/WebViewJavascriptBridge
- IOS(WKWebview): https://github.com/Lision/WKWebViewJavascriptBridge
- Android: https://github.com/lzyzsd/JsBridge
安装
使用npm安装:
npm install native-jsbridge --save-dev
使用
- js调用原生方法
import { callNative } from "native-jsbridge";
callNative({
method: "exampleMethod",
data: { id: 5 },
callback(response){
console.log("来源于原生的反馈信息: " + response);
}
})
- 原生调用JS方法
import { bridgeRegisterHandler } from "native-jsbridge";
bridgeRegisterHandler({
method: "exampleMethod",
data: {option: 'xxxxx'}, // 原生那边回调可以拿到的参数数据
callback(data){
console.log("原生传递给前端的data: " + data);
}
})