1.0.4 • Published 2 years ago
mjsbridge v1.0.4
- npm install mjsbridge -S
- import webviewBridge from 'mjsbridge'
// Trigger the natively written registration monitoring event'testView', and pass the data
webviewBridge.emit('testView', {a: 1, b: 2}, function() { // params {a: 1, b: 2} Object form can be used directly, JSON string has been converted internally
// to do something
})
webviewBridge.on('testView2', function(data, responseCallback) { // data is the transmitted data
// to do something
const d = JSON.parse(data) // Note that the received data must be parsed as a JSON object
// Example code logic
if (Number(d.dataKey) === 123) {
responseCallback(JSON.stringify({color: 'black 321'})) // If you need to send data to the native client, pay attention to JSON string transmission
} else {
responseCallback(data)
}
})