1.项目中引入 DSBridge.js 文件

var bridge = {
default: this,
call: function(b, a, c) {
var e = "";
"function" == typeof a && (c = a, a = {});
a = {
data: void 0 === a ? null : a
};
if ("function" == typeof c) {
var g = "dscb" + window.dscb++;
window[g] = c;
a._dscbstub = g
}
a = JSON.stringify(a);
if (window._dsbridge) e = _dsbridge.call(b, a);
else if (window._dswk || -1 != navigator.userAgent.indexOf("_dsbridge")) e = prompt("_dsbridge=" + b, a);
return JSON.parse(e || "{}").data
},
register: function(b, a, c) {
c = c ? window._dsaf : window._dsf;
window._dsInit || (window._dsInit = !0, setTimeout(function() {
bridge.call("_dsb.dsinit")
},
0));
"object" == typeof a ? c._obs[b] = a : c[b] = a
},
registerAsyn: function(b, a) {
this.register(b, a, !0)
},
hasNativeMethod: function(b, a) {
return this.call("_dsb.hasNativeMethod", {
name: b,
type: a || "all"
})
},
disableJavascriptDialogBlock: function(b) {
this.call("_dsb.disableJavascriptDialogBlock", {
disable: !1 !== b
})
}
};
! function() {
if (!window._dsf) {
var b = {
_dsf: {
_obs: {}
},
_dsaf: {
_obs: {}
},
dscb: 0,
dsBridge: bridge,
close: function() {
bridge.call("_dsb.closePage")
},
_handleMessageFromNative: function(a) {
var e = JSON.parse(a.data),
b = {
id: a.callbackId,
complete: !0
},
c = this._dsf[a.method],
d = this._dsaf[a.method],
h = function(a, c) {
b.data = a.apply(c, e);
bridge.call("_dsb.returnValue", b)
},
k = function(a, c) {
e.push(function(a, c) {
b.data = a;
b.complete = !1 !== c;
bridge.call("_dsb.returnValue", b)
});
a.apply(c, e)
};
if (c) h(c, this._dsf);
else if (d) k(d, this._dsaf);
else if (c = a.method.split("."), !(2 > c.length)) {
a = c.pop();
var c = c.join("."),
d = this._dsf._obs,
d = d[c] || {},
f = d[a];
f && "function" == typeof f ? h(f, d) : (d = this._dsaf._obs, d = d[c] || {}, (f = d[a]) && "function" == typeof f &&
k(f, d))
}
}
},
a;
for (a in b) window[a] = b[a];
bridge.register("_hasJavascriptMethod", function(a, b) {
b = a.split(".");
if (2 > b.length) return !(!_dsf[b] && !_dsaf[b]);
a = b.pop();
b = b.join(".");
return (b = _dsf._obs[b] || _dsaf._obs[b]) && !!b[a]
})
}
}();

2.引入

import '../../util/DSBridge.js'

3.与原生交互

1.给原生传参数

var obj = {
  data : 'getDiagnosisImg ' ,
  name : ' img '
}
dsBridge.call ( "AddImg" , obj)

js通过dsBridge.call() 方法传值
第一个参数:AddImg是约定注册的名称,与原生接收处方法名一致;
第二个参数是要传递的参数;

2.接收原生传给uni的值

dsBridge.register ( "getDiagnosis Img" , (res) =>{
  console.log (res)
})

第一个参数:getDiagnosisImg 是注册方法名,与原生保持一致;
第二个是js的方法,参数res就是原生返回给uni的值;

最新文章

  1. Linux下安装tensorflow
  2. [转] Spring MVC sample application for downloading files
  3. 在VS项目中通过GIT生成版本号作为编译版本号
  4. Meteor 使用疑问总结
  5. AIM Tech Round (Div. 2) A. Save Luke 水题
  6. HDU 2340 Obfuscation(dp)
  7. C++ list用法
  8. Android Studio稍微较新的版本下载
  9. baidu-fex 精彩文章
  10. android手机安全卫士、Kotlin漫画、支付宝动画、沉浸状态栏等源码
  11. 白瑜庆:知乎基于Kubernetes的kafka平台的设计和实现
  12. 从0到1:使用Caliburn.Micro(WPF和MVVM)开发简单的计算器
  13. jquery快速入门(一)
  14. CRT/LCD/VGA Information and Timing
  15. N!的近似值_斯特林公式
  16. 远程IPC种植木马
  17. 一个快速检测系统CPU负载的小程序
  18. SpringBoot读取war包jar包Resource资源文件解决办法
  19. Xcode8的调试技能Memory Graph 实战解决闭包引用循环问题
  20. 解决Ajax请求跨域问题

热门文章

  1. Nacos服务调用(基于Openfeign)
  2. [EULAR文摘] TNFi治疗3年对384例强柱患者脊柱放射学进展的影响
  3. .net 定时任务(调度 .net quartz) demo
  4. 基于Ubuntu搭建OpenGL开发环境
  5. 线性表的顺序存储C++代码
  6. 🤗 PEFT: 在低资源硬件上对十亿规模模型进行参数高效微调
  7. ESModule导入
  8. ES搜索- term与match区别&bool查询
  9. ACGAN-pytorch
  10. iOS开发-应用评分引导