kntt / vue-js-bridge Goto Github PK
View Code? Open in Web Editor NEWvue-js-bridge for Vue.js
License: MIT License
vue-js-bridge for Vue.js
License: MIT License
@Kntt ,从文档上看,
1、只看到h5提供数据的两种方法给移动端,但是移动端不知道怎么接收,
2、如果移动端要传输数据给h5,h5怎么接收处理数据
我现在的流程是
创建并初始化WebView ->
加载url ->
200毫秒后,安卓端注册 webView.registerHandler("callNativeHandler", new BridgeHandler()...)->
Vue页面mounted()方法里this.$bridge.registerHandler('callJsHandler', (msg, callback)...) ->
1000毫秒后,Vue调用this.$bridge.callHandler(...)
控制台看到的结果是
安卓端注册
vue启动
js注册
然后就显示 java.io.FileNotFoundException: WebViewJavascriptBridge.js
chromium给出"Uncaught ReferenceError: WebViewJavascriptBridge is not defined"
这种情况是我注册的时机不对吗?
您的东西,我研究了好几天了,跟IOS调试两个方法都没有问题,但是安卓端调取我的方法调不通
async callNative() {
try {
await this.$bridge
.callHandler({
type: "Log",
data: {
name: "test js bridge"
}
})
.then(res => {
console.log("native-res", res);
this.code = res;
});
} catch (error) {
console.log("error", error);
}
}
Vue.use(VueJsBridge, {
debug: true,
nativeHandlerName: "SLJsBridge",
mock: false,
mockHandler(payload, next) {
// mock by payload
// call next(data) to mock data
next(Object.assign({ form: "native" }, payload));
}
});
然后原生同事那边约定好 这个名字 但是调用的时候就 打印start calling nativeHandler with payload 之后就没有反应了 但是直接 用 SLJsBridge.Log() 就可以调用成功。原生那边应该怎么写呢 还是现在写的这些有问题
callNative() {
console.log("click");
try {
this.$bridge
.callHandler({
type: "Log",
data: {
name: "test js bridge"
}
})
.then(res => {
console.log("native-res", res);
this.code = res;
});
} catch (error) {
console.log("error", error);
}
}
这段代码 ios 可以走到.then 但是 安卓走不进来
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.