【普通json数组】

针对官方的普通json数组示例,做些填充

 <template>
<view>
<view class="uni-title uni-common-pl">地区选择器</view>
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker @change="bindPickerChange" :value="index" :range="array">
<view class="uni-input">{{array[index]}}</view>
</picker>
</view>
</view>
</view> <view class="uni-title uni-common-pl">地区选择器(普通Json数组)</view>
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker @change="bindPickerChanges" range-key="name" :data-index="22" :data-id="objectArray[index].id" :value="index" :range="objectArray">
<view class="uni-input">{{objectArray[index].name}}</view>
<!-- 还是建议用input保存,可能picker更新不及时 -->
<input type="text" :value="objectArray[index].id" hidden/>
</picker>
</view>
</view>
</view> <view class="uni-title uni-common-pl">时间选择器</view>
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker mode="time" :value="time" start="09:01" end="21:01" @change="bindTimeChange">
<view class="uni-input">{{time}}</view>
</picker>
</view>
</view>
</view> <view class="uni-title uni-common-pl">日期选择器</view>
<view class="uni-list">
<view class="uni-list-cell">
<view class="uni-list-cell-db">
<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
<view class="uni-input">{{date}}</view>
</picker>
</view>
</view>
</view>
</view>
</template> <script>
export default {
data() {
const currentDate = this.getDate({
format: true
})
return {
title: 'picker',
array: ['中国', '美国', '巴西', '日本'],
objectArray: [{
id: 11,
name: '中国'
},
{
id: 12,
name: '美国'
},
{
id: 13,
name: '德国'
},
{
id: 14,
name: '法国'
}
],
index: 0,
date: currentDate,
time: '12:01'
}
},
computed: {
startDate() {
return this.getDate('start');
},
endDate() {
return this.getDate('end');
}
},
methods: {
bindPickerChange: function(e) {
console.log('picker发送选择改变,携带值为', e.target.value)
this.index = e.target.value
},
bindPickerChanges: function(e) {
this.index = e.detail.value
console.log('可以传data-xx:xx',e.currentTarget.dataset.index,'\n默认传过来的是下标:',e.detail.value,'\n也可以传普通json传过来的id等:',e.currentTarget.dataset.id);
},
bindDateChange: function(e) {
this.date = e.target.value
},
bindTimeChange: function(e) {
this.time = e.target.value
},
getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate(); if (type === 'start') {
year = year - 60;
} else if (type === 'end') {
year = year + 2;
}
month = month > 9 ? month : '0' + month;;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
}
}
}
</script>

最新文章

  1. [原创]MySQL innodb_rollback_on_timeout参数对锁的影响
  2. vue
  3. Python-面向对象编程(二)
  4. jQuery自定义滚动条样式插件mCustomScrollbar
  5. [故障处理]联想笔记本故障0x0000007B
  6. iOS开发:cocoapods的使用
  7. 深入理解计算机系统第二版习题解答CSAPP 2.18
  8. HTML5 WebAudioAPI-实例(二)
  9. C++_知识点_全局变量
  10. 移动端的click
  11. Jetty:配置JSP支持
  12. sql注入基础(原理)
  13. data.go
  14. CTF取证方法大汇总,建议收藏!
  15. sqlparameters
  16. winform里面的Form1.Designer.cs
  17. Java中的char占用几个字节
  18. python(leetcode)-48旋转图像
  19. Android 梯形进度条、下载进度条;
  20. Linux:从文件中搜索关键字并显示行数(cat,grep函数)

热门文章

  1. linux技能点 六 软件管理和其他命令
  2. suoermap的object.net循环遍历属性表,从数据库取数据进行更新属性字段值
  3. MySQL Index--Change Buffer
  4. win下maridb 10.1.8下主从复制配置
  5. 云服务器CentOS7.4下搭建GitLab
  6. C#中的WinForm的消息机制简述,及消息机制下Invoke,和BeginInvoke的使用和区别
  7. ML.NET学习笔记 ---- 系列文章
  8. 微信之获取微信的openid(二)详细版
  9. js Date对象和数字对象
  10. MSc in Robotics