plus使用注意事项 plusready react


plus plusready 使用注意事项 react

零、前言

这段时间写HTML5+项目时 遇到一个plusReady的问题
运用plus时一定要先plusReady

一、代码展示

一般plusready在componentDidmount中就执行

//在挂载之后进行  很重要  一定要有
componentDidMount(){
   if(window.plus){//当有plus时,直接plusPredy
     this.plusReady();
   }else{//当没有plus时,要先创造plusready事件
     document.addEventListener('plusready',this.plusReady,false);
   }
 }

 //plusReady函数  在这里才能调用plus api
 plusReady=()=>{
   // 在这里调用plus api
     this.creatBarCode()
   
 }
 // 创建barcode控件  使用plus api的地方
 creatBarCode() {
   if (!barcode) {
     barcode = plus.barcode.create('barcode', [plus.barcode.QR], {
       top:'100px',
       left:'0px',
       width: '100%',
       height: '500px',
       position: 'static'
     });
     barcode.onmarked = function (type, result) {
       alert('扫描结果:'+result)
     };
     plus.webview.currentWebview().append(barcode);
   }
   barcode.start();
 }

二、总结需要plusready的h5+API

这里我只记录我知道的,不知道的就没写啦

1.缓存 plus.storage

存:一定要 取:一定要 清空:不清楚

2.文件 plus.io

存:好像不用 取:一定要的

3.扫码 plus.barcode

一定要

4.相册 plus.gallery

好像不用

5.按键 plus.key

应该要吧

6.原生界面 plus.NativeUI

不清楚

7.页面:plus.webview

好像不用


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM