效果图
完整代码
<template>
<view>
<picker mode="date" fields="month" :value="date" @change="bindDateChange">
<view class="uni-input">{{date}}</view>
</picker>
</view>
</template>
<script>
export default {
data() {
return {
date: this.getCurrentMonth()
}
},
methods: {
bindDateChange: function(e) {
this.date = e.target.value
console.log(this.date)
},
getCurrentMonth () {
const date = new Date()
let year = date.getFullYear()
let month = date.getMonth() + 1
month = month > 9 ? month : '0' + month
return `${year}-${month}`
}
}
}
</script>
<style>
</style>
官方手册
picker | uni-app官网https://uniapp.dcloud.io/component/picker.html#picker
封面