Loading…

Check barcode Demo

# Preface This tutorial is based on the "apifm-wxapi" module and teaches you how to quickly implement small program development, so you may need to understand the following knowledge points first: ["Creating HelloWorld Project"](https://www.yuque.com/apifm/doc/hezlrm) ["Use "apifm-wxapi" to quickly develop small programs"](https://www.yuque.com/apifm/doc/mdldsd) ["Register for free to open the backend and obtain an exclusive domain name"](https://www.yuque.com/apifm/doc/qr6l4m) # Function description There is a barcode on the outer packaging of any product; This example demonstrates how to quickly input barcodes to query product information; # Mini program implementation ## Effect demonstration ![](https://dcdn.it120.cc/yuque/0/2019/png/572726/1572848441464-1eca8397-01c8-4232-abc3-bccda4a24782.png) ## wxml code ```plain Product barcode query barcode ``` ## js code ```plain const WXAPI = require('apifm-wxapi') WXAPI.init('gooking') Page({ data: { barcode: undefined }, onLoad: function (options) { }, onShow: function () { }, barcodeChange(e){ this.data.barcode = e.detail.value }, queryBarcode() { // Query barcode if (!this.data.barcode){ wx.showToast({ title: 'Barcode cannot be empty', icon: 'none' }) return } WXAPI.queryBarcode(this.data.barcode).then(res => { console.log(res) if (res.code == 0) { wx.showToast({ title: 'Query successful', icon: 'success' }) } else { wx.showToast({ title: res.msg, icon: 'none' }) } }) } }) ``` > WXAPI.init('gooking') This code links your mini program to your backend, where gooking is your exclusive domain name (please check the chapter about exclusive domain names in the preface); > _Using the code scanning API of the mini program, you can easily call the WeChat code scanning interface to quickly scan the code to read the barcode and then query it_ **Expansion:** _Using this function, you can try to develop a small program for purchasing, selling, inventory, and warehousing based on product barcodes. Remember to share it with everyone~_ Looking forward to your progress! grateful!