一:实现扫一扫
分享者:向往蓝天的飞鱼,来自原文地址
//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的源是数组的情形,range-key制定了需要picker展示的内容。index是系统自动指定的array的下标,不用修改。
对应的数组内容如下:
-
[{
-
"id": "XM4xZnN088X5",
-
"name": "西双版纳州"
-
}, {
-
"id": "yrw6F6n30igs",
-
"name": "昆明市"
-
}]
注意range-key中的字段需要单引号指定。
|