scan-code.uvue 889 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <view>
  3. <page-head :title="title"></page-head>
  4. <view class="uni-padding-wrap uni-common-mt">
  5. <view class="uni-title">扫码结果:</view>
  6. <view v-if="result" class="scan-result">
  7. {{result}}
  8. </view>
  9. <view class="uni-btn-v">
  10. <button type="primary" @click="scan">扫一扫</button>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script lang="uts">
  16. export default {
  17. data() {
  18. return {
  19. title: 'scanCode',
  20. result: ''
  21. }
  22. },
  23. methods: {
  24. scan() {
  25. uni.scanCode({
  26. success: (res: ScanCodeSuccess) => {
  27. console.log('res: ',res);
  28. this.result = res.result
  29. },
  30. fail: (err: ScanCodeFail) => {
  31. console.log('err: ',err);
  32. // 需要注意的是小程序扫码不需要申请相机权限
  33. }
  34. });
  35. }
  36. }
  37. }
  38. </script>
  39. <style>
  40. .scan-result {
  41. min-height: 25px;
  42. line-height: 25px;
  43. }
  44. </style>