<template> <view style="margin-top: 200rpx;"> <view> <picker :range="years" :value="echoVal" @change="yearChange" mode="multiSelector"> {{ years[0][yearsIndex1] }}-{{ years[1][yearsIndex2] }} </picker> </view> </view> </view> </template> <script> export default { data() { return { years: [], yearsIndex1: 0, yearsIndex2: 0, echoVal: [], //当前日期回显 } }, // 页面加载 onLoad(e) { var date = new Date(); var year = date.getFullYear(); //获取完整的年份(4位) var month = date.getMonth() + 1; //获取当前月份(0-11,0代表1月) var nowDay = date.getDate(); //获取当前日(1-31) this.yearsIndex1 = year - 1500; //回显年 this.yearsIndex2 = month - 1; //回显月 let numbers = []; for (let i = 1500; i <= 2999; i++) { numbers.push(i); } var arr = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']; this.years.push(numbers); //下拉组合 this.years.push(arr); //下拉组合 this.echoVal.push(year - 1500); //回显年 this.echoVal.push(month - 1); //回显月 }, methods: { yearChange: function(e) { console.log(e) //获得对象的 detail的 value //通过数组的下标改变显示在页面的值 this.yearsIndex1 = e.detail.value[0]; this.yearsIndex2 = e.detail.value[1]; } } } </script> <style> </style>