上才艺
使用async await 处理异步方法
<template>
<view class="">
<view class="sss" @click="show = true">
<text>日期选择</text>
<u-datetime-picker :show="show" v-model="timeValue" mode="date"
@confirm="confirm" @cancel="close"></u-datetime-picker>
<view>{{ timeValue }}</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
show: false,
timeValue: '2022-05-21',
value1: Number(new Date())
};
},
methods: {
async confirm(e) {
this.show = false;
const timeFormat = uni.$u.timeFormat;
let timeValue = await timeFormat(e.value, 'yyyy-mm-dd');
//可以自己更改格式 例:'yyyy-mm-dd hh:MM'
this.timeValue = timeValue;
console.log(timeValue);
},
console.log(timeFormat(e.value, 'yyyy-mm'));
close() {
this.show = false;
}
}
};
</script>