一:實現(xiàn)掃一掃
分享者:向往藍天的飛魚,來自原文地址
//index.js
-
//獲取應用實例
-
var app = getApp()
-
Page({
-
data: {
-
show: "",
-
},
-
-
onLoad: function () {
-
console.log('onLoad')
-
},
-
click: function () {
-
var that = this;
-
var show;
-
wx.scanCode({
-
success: (res) => {
-
this.show = "--result:" + res.result + "--scanType:" + res.scanType + "--charSet:" + res.charSet + "--path:" + res.path;
-
that.setData({
-
show: this.show
-
})
-
wx.showToast({
-
title: '成功',
-
icon: 'success',
-
duration: 2000
-
})
-
},
-
fail: (res) => {
-
wx.showToast({
-
title: '失敗',
-
icon: 'success',
-
duration: 2000
-
})
-
},
-
complete: (res) => {
-
}
-
.saoma{
-
height: 40px;
-
width:110px;
-
line-height: 40px;
-
margin-left: auto;
-
margin-right: auto;
-
color: #fff;
-
background-color: #999;
-
text-align: center;
-
}
-
.show{
-
width: 100%;
-
color: #666;
-
background-color: #fff;
-
height: auto;
-
-
}
-
<view class="container">
-
<view class="saoma" bindtap="click">點我掃一掃</view>
-
<view class="show">{{show}}</view>
-
</view>
微信小程序,真機測試通過
二:picker和range-key的用法
分享者:獨鳴在彼岸,來自原文地址
-
<picker bindchange="bindPickerChange" value="{{index}}" range="{{location}}" range-key="{{'name'}}">
-
<view class="picker">
-
地州{{location[index]}}
-
</view>
-
</picker>
range-key用于渲染picker的源是數(shù)組的情形,range-key制定了需要picker展示的內(nèi)容。index是系統(tǒng)自動指定的array的下標,不用修改。
對應的數(shù)組內(nèi)容如下:
-
[{
-
"id": "XM4xZnN088X5",
-
"name": "西雙版納州"
-
}, {
-
"id": "yrw6F6n30igs",
-
"name": "昆明市"
-
}]
注意range-key中的字段需要單引號指定。
|