今天來做下小程序掃一掃功能回官,因為項目需要曹宴,需要在頁面搜索框加上掃碼功能。
廢話不多說歉提,直接上代碼笛坦。
wxml代碼
<view class="search">
<view class="search-left">
<input type="number" cpmfirm-type="search" placeholder='輸入單號,查找訂單' placeholder-style="color: rgba(255, 255, 255, 0.9); " value="{{scanCodeMsg}}"></input>
<view bindtap='scanCode' class="iconfont icon-saoma"> </view>
</view>
</view>
js代碼:
//掃碼
scanCode: function () {
var that = this;
wx.scanCode({ //掃描API
success(res) { //掃描成功
console.log(res) //輸出回調(diào)信息
that.setData({
scanCodeMsg: res.result
});
wx.showToast({
title: '掃碼成功',
icon: 'success',
duration: 1000
})
},
fail: (res) => {//接口調(diào)用失敗的回調(diào)函數(shù)
wx.showToast({
title: '掃碼失敗',
icon: 'success',
duration: 1000
})
},
})
}