实现效果:
html代码:
<u-picker mode="time" :defaultTime="defaultTime" v-model="show" :params="params" end-year="2030"
@confirm="confirm"></u-picker>
js 代码:
数据:
show: false,
defaultTime: "",
params: {
year: true,
month: true,
day: true,
hour: true,
minute: true,
second: true,
timestamp: true
}
// 获取系统默认时间
onLoad() {
var date = new Date(),
year = date.getFullYear(),
month = date.getMonth() + 1,
day = date.getDate(),
hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
month >= 1 && month <= 9 ? (month = "0" + month) : "";
day >= 0 && day <= 9 ? (day = "0" + day) : "";
var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
this.defaultTime = timer
},
methods: {
confirm(params) {
console.log(params)
}
}