|
本系列主要是從活動(dòng)中將參與者分享的代碼片斷凝成一個(gè)系列:
你可以在這里分享自己的代碼片斷,會(huì)在下一篇文章中加入你的分享的代碼片斷:
分享實(shí)用代碼片斷活動(dòng),分享5個(gè)片斷額外獎(jiǎng)勵(lì)一個(gè)月VIP會(huì)員
本次由 ETL分享
一:掃碼
目的
方便用戶輸入數(shù)據(jù),部分?jǐn)?shù)字?jǐn)?shù)據(jù),如飲料瓶上的條碼輸入,可以直接使用掃碼讀入數(shù)據(jù)
wxml代碼
-
<view>
-
<input name="termSeq" placeholder="*機(jī)器號(hào)" value="{{termSeq}}" /> //放數(shù)據(jù)用的input
-
<image src="../../pages/images/timg.jpg" bindtap="getseq"/> //點(diǎn)擊圖片啟動(dòng)攝像頭掃碼
-
</view>
js代碼
-
getseq: function (e) {
-
var _that = this;
-
wx.scanCode({
-
success: function (res) {
-
console.log("成功")
-
console.log(res)//打印res查看掃碼結(jié)果
-
if (res.result) {//將得到的數(shù)據(jù)放到input輸入框去
-
_that.setData({
-
termSeq: res.result
-
})
-
}
-
},
-
fail: function (res) {
-
console.log("失敗")
-
console.log(res)
-
}
-
})
-
}
二:下拉刷新
目標(biāo) 用戶拉下的時(shí)候,可以刷新當(dāng)前頁(yè)面
刷新需要在app.json 添加代碼 app.json代碼 放在pages下面
-
,
-
"window": {
-
"enablePullDownRefresh": true
-
}
js代碼
-
onPullDownRefresh: function () {
-
//這里寫用戶下拉的時(shí)候你執(zhí)行的動(dòng)作,如:發(fā)起wx.request請(qǐng)求一次,或者其他請(qǐng)求
-
console.log("下拉刷新")
-
setTimeout(()=>{
-
wx.stopPullDownRefresh()//表示停止刷新
-
},1000) //這是表示多久后執(zhí)行下拉停止
-
}
|