项目地址:https://github.com/wkl007/vue-scan-demo.git

项目主要是做的一个扫码的功能

核心代码为

  1. <div class="scan">
  2. <div id="bcid">
  3. <div style="height:40%"></div>
  4. <p class="tip">...载入中...</p>
  5. </div>
  6. <footer>
  7. <button @click="startRecognize">1.创建控件</button>
  8. <button @click="startScan">2.开始扫描</button>
  9. <button @click="cancelScan">3.结束扫描</button>
  10. <button @click="closeScan">4.关闭控件</button>
  11. </footer>
  12. </div>
  13. </template>
  14. <script type='text/ecmascript-6'>
  15. let scan = null
  16. export default {
  17. data () {
  18. return {
  19. codeUrl: '',
  20. }
  21. },
  22. methods: {
  23. // 创建扫描控件
  24. startRecognize () {
  25. let that = this
  26. if (!window.plus) return
  27. scan = new plus.barcode.Barcode('bcid')
  28. scan.onmarked = onmarked
  29. function onmarked (type, result, file) {
  30. switch (type) {
  31. case plus.barcode.QR:
  32. type = 'QR'
  33. break
  34. case plus.barcode.EAN13:
  35. type = 'EAN13'
  36. break
  37. case plus.barcode.EAN8:
  38. type = 'EAN8'
  39. break
  40. default:
  41. type = '其它' + type
  42. break
  43. }
  44. result = result.replace(/\n/g, '')
  45. that.codeUrl = result
  46. alert(result)
  47. that.closeScan()
  48. }
  49. },
  50. // 开始扫描
  51. startScan () {
  52. if (!window.plus) return
  53. scan.start()
  54. },
  55. // 关闭扫描
  56. cancelScan () {
  57. if (!window.plus) return
  58. scan.cancel()
  59. },
  60. // 关闭条码识别控件
  61. closeScan () {
  62. if (!window.plus) return
  63. scan.close()
  64. },
  65. }
  66. }
  67. </script>
  68. <style lang="less">
  69. .scan {
  70. height: 100%;
  71. #bcid {
  72. width: 100%;
  73. position: absolute;
  74. left: 0;
  75. right: 0;
  76. top: 0;
  77. bottom: 3rem;
  78. text-align: center;
  79. color: #fff;
  80. background: #ccc;
  81. }
  82. footer {
  83. position: absolute;
  84. left: 0;
  85. bottom: 1rem;
  86. height: 2rem;
  87. line-height: 2rem;
  88. z-index: 2;
  89. }
  90. }
  91. </style>

vue项目中实现扫码功能的更多相关文章

  1. Vue项目中添加锁屏功能

    0. 直接上 预览链接 Vue项目中添加锁屏功能 1. 实现思路 ( 1 ) 设置锁屏密码 ( 2 ) 密码存localStorage (本项目已经封装h5的sessionStorage和localS ...

  2. vue项目中导出Excel文件功能的前端代码实现

    在项目中遇到了两种不同情况, 1.get请求导出文件,实现起来相对简单 // 导出数据 exportData() { window.location.href = `/oes-content-mana ...

  3. 在vue项目中使用codemirror插件实现代码编辑器功能(代码高亮显示及自动提示

    在vue项目中使用codemirror插件实现代码编辑器功能(代码高亮显示及自动提示) 1.使用npm安装依赖 npm install --save codemirror; 2.在页面中放入如下代码 ...

  4. vue移动app扫码功能

    第一步: 上面这段代码写在index.html里面,我也不知道为什么,可能是全局的关系: 第二步: 定义一个按钮,点击启动扫码功能,另外再定义一个盒子来当做扫码的容器:我给这个盒子定义了一个id类名: ...

  5. 转:如何在Vue项目中使用vw实现移动端适配

    https://www.w3cplus.com/mobile/vw-layout-in-vue.html 有关于移动端的适配布局一直以来都是众说纷纭,对应的解决方案也是有很多种.在<使用Flex ...

  6. 在Vue项目中使用vw实现移动端适配

    有关于移动端的适配布局一直以来都是众说纷纭,对应的解决方案也是有很多种.在<使用Flexible实现手淘H5页面的终端适配>提出了Flexible的布局方案,随着viewport单位越来越 ...

  7. 如何在Vue项目中使用vw实现移动端适配(转)

    有关于移动端的适配布局一直以来都是众说纷纭,对应的解决方案也是有很多种.在<使用Flexible实现手淘H5页面的终端适配>提出了Flexible的布局方案,随着viewport单位越来越 ...

  8. 如何在Vue项目中使用vw实现移动端适配

    有关于移动端的适配布局一直以来都是众说纷纭,对应的解决方案也是有很多种.在< 使用Flexible实现手淘H5页面的终端适配>提出了Flexible的布局方案,随着 viewport 单位 ...

  9. ionic3 实现扫码功能

    ionic3 通过插件phonegap-plugin-barcodescanner,调用机器硬件摄像头实现扫码功能. 首先当然先了解下 phonegap-plugin-barcodescanner,这 ...

随机推荐

  1. Vue的指令和成员

    目录 Vue的指令和成员 指令 表单 斗篷 条件 循环 成员 计算成员 监听成员 Vue的指令和成员 指令 表单 表单指令一般是和属性指令联合使用的,最常见的就是v-model="变量&qu ...

  2. Django之13种必会查询

    1.常见的13中查询方式(必须记住) <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> g ...

  3. java_网络编程之上传文件案例

    初期成果: 客户端: package FileUpload; import java.io.*; import java.net.Socket; import java.util.Scanner; p ...

  4. Android开发 BottomNavigationView学习

    前言 注意这个里介绍的是AndroidX的com.google.android.material.bottomnavigation.BottomNavigationView xml布局中 <co ...

  5. HTML - 文本标签相关

    <html> <head></head> <body> <!-- 标题标签 : h1到h6, 文字大小依次变小, 加粗显示, 自带换行 标签中的部 ...

  6. 【玲珑杯 round#18 A】计算几何你瞎暴力

    [Link]:http://www.ifrog.cc/acm/problem/1143?contest=1020&no=0 [Description] [Solution] 因为每个点的(xi ...

  7. linux top命令VIRT,RES,SHR,DATA的含义(转)

    linux top命令VIRT,RES,SHR,DATA的含义 字体: 大 小Posted by 佚名 | tags: top  VIRT  RES  SHR VIRT:virtual memory ...

  8. js封装设置获取cookie

    var docCookies = { getItem: function (sKey) { return decodeURIComponent(document.cookie.replace(new ...

  9. 关于新手必须要理解的几个名词,cookie、session和token

    以下要说的,虽然不是开发过程中必须会遇到的,但却是进阶之路上必须要掌握的,一些涉及到状态管理与安全的应用当中尤为重要. 我之前虽略有学习,但也是东拼西凑临时看的一点皮毛,所以在这个假期利用一点时间,整 ...

  10. PAT甲级——A1075 PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...