钉钉小程序最快实现扫码功能

1.使用npm安装

npm install dingtalk-jsapi --save

2.在所需要的界面js,引入

import * as ddcode from "dingtalk-jsapi";

3\

 scanCode(){ 
    ddcode.biz.util.scan({
    type: String , // type 为 all、qrCode、barCode,默认是all。
    onSuccess: function(data) {  
        //onSuccess将在扫码成功之后回调
      	/* data结构
        	{ 'text': String}
      	*/ 
      	console.log(data.text)
    },
   onFail : function(err) {
      alert('失败')
   }
})
    }

html:
在这里插入图片描述

  <view class="scanCode" onTap="scanCode">扫一扫</view>