barcode.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view class="barcode">
  3. <text>条码类型{{scanType}}</text>
  4. <view class="ba1">
  5. <text>条码内容{{result}}</text>
  6. </view>
  7. <button type="primary" class="but" @click="sc">扫码</button>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. components:{
  13. },
  14. data() {
  15. return {
  16. scanType:"",
  17. result:"",
  18. }
  19. },
  20. onHide() {
  21. uni.stopBluetoothDevicesDiscovery({
  22. success(res) {
  23. console.log(res)
  24. }
  25. })
  26. uni.closeBluetoothAdapter({
  27. success(res) {
  28. console.log(res)
  29. }
  30. })
  31. },
  32. mounted() {
  33. },
  34. methods: {
  35. sc(){
  36. uni.scanCode({
  37. success: (res) => {
  38. console.log('条码类型:' + res.scanType);
  39. this.result = res.result
  40. this.scanType = res.scanType
  41. console.log('条码内容:' + res.result);
  42. },
  43. fail:(e) =>{
  44. console.log(e)
  45. }
  46. });
  47. }
  48. }
  49. }
  50. </script>
  51. <style scoped lang="scss">
  52. .barcode {
  53. padding:60rpx 20rpx;
  54. .ba1{
  55. margin:30rpx 0;
  56. }
  57. }
  58. .but{
  59. margin:50rpx;
  60. }
  61. </style>