日期选择器之前是这样写的:
<picker mode="date" :value="date" start="" end="" @change="bindDateChange">
<view class="picker">
<text class="tishi2">{
{date}}</text>
</view>
</picker>
打包Android安装到手机上不能选择日期,原因是没设置 start 和 end的属性值,设置这两值就能选择了:
<template>
<view class="container">
<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
<text>{
{date}}</text>
</picker>
</view>
</template>
<script>
function getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (type === 'start') {
year = year - 100;
} else if (type === 'end') {
year = year + 100;
}
month = month > 9 ? month : '0' + month;;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
}
export default {
data() {
return {
date: getDate({
format: true
}),
startDate:getDate('start'),
endDate:getDate('end'),
}
},
methods: {
//日期选择
bindDateChange: function(e) {
this.date = e.detail.value
}
},
onLoad() {
}
}
</script>
<style>
</style>