LightJSBridge

LightJSBridge 模块可以让jsnative调用native原生的功能。

注意:
LightJSBridge模块目前只在我们JSNative app端支持,web端不支持

API

call (methodname,params, callback)

可以无缝的调用web容器中的LightJSAPI的功能

参数

  • methodname {string}:jsApi的方法名
  • params{object}:选项参数对象
  • callback:回调方法

示例

<template>
<div>
<text class="item" @click="onClick('native.getUDID')">native.getUDID</text>
<text class="item" @click="onClick('native.back')">native.back</text>
<text class="item" @click="onClick('native.close')">native.close</text>
<text class="item" @click="onClick('native.getSystemInfo')">native.getSystemInfo</text>
<text class="item" @click="onClick('native.writeData')">native.writeData</text>
<text class="item" @click="onClick('native.readData')">native.readData</text>
<text class="item" @click="onClick('native.deleteData')">native.deleteData</text>
<text class="item" @click="onClick('native.chooseImage')">native.chooseImage</text>
<div v-if="isShowResult" >
<text style="text-align:left;font-size:32;padding:20;color:white;background-color:red;" @click="onClose" >返回</text>
<image style="width:700;height:700;" v-if="imageSrc!=''" :src="imageSrc"></image>
<text :value="result"></text>
</div>
</div>

</template>

<script>
var LightJSBridge = Light.requireModule('LightJSBridge');
var modal =Light.requireModule('modal');
module.exports = {
data:function(){
return{
isShowResult:false,
imageSrc:'',
result:""
}
},
created:function(){
},
methods:{
onClick:function(action){
var that = this;
var param = {};
if ("native.writeData" == action){
param.key = "writeDataKey";
param.value = "writeData_test";
param.scope = "jsnative";
param.domain = "memory";
}else if ("native.readData" == action){
param.key = "writeDataKey";
param.scope = "jsnative";
param.domain = "memory";
}else if ("native.deleteData" == action){
param.key = "writeDataKey";
param.scope = "jsnative";
param.domain = "memory";
}
LightJSBridge.call(action,param,function(ret){
that.isShowResult = true;
that.imageSrc= '';
that.result = '';
if (action == "native.chooseImage"){
that.imageSrc= "data:image/png;base64," + ret.data.result;
}else{
that.result = JSON.stringify(ret);
}
});
}
}
}
</script>