diff --git a/docs/component/picker-view.md b/docs/component/picker-view.md index 762bb218467f7600ffd6d34bc27ec1d6b95b00a1..ac9593d56c95ae467d717aac8a672249930fea5f 100644 --- a/docs/component/picker-view.md +++ b/docs/component/picker-view.md @@ -84,16 +84,86 @@ day, value: [9999, month - 1, day - 1], visible: true, - indicatorStyle: `height: 50px;` + indicatorStyle: `height: 50px;`, + + mouthArr1:[1,3,5,7,8,10,12],//31天的数据 + mouthArr2:[4,6,9,11],//30天的数据 } }, + //2022-07-08新增监听事件,因为以前没有判断到,监听到每个月的时间----------> + watch: { + year: { + // 数据发生变化就会调用这个函数 + handler(newVal) { + this.showDate() + }, + // 立即处理 进入页面就触发 + immediate: true + }, + month:{ + // 数据发生变化就会调用这个函数 + handler(newVal) { + this.showDate() + }, + // 立即处理 进入页面就触发 + immediate: true + } + }, + //--------------------------------> methods: { bindChange: function (e) { const val = e.detail.value this.year = this.years[val[0]] this.month = this.months[val[1]] this.day = this.days[val[2]] - } + + //由于判断太多建议封装成组件形式,将值通过emit子传父 + /*let obj = { + year:this.year, + month:this.month, + day:this.day, + }*/ + //this.$emits('事件名',obj)即可 + }, + // 判断修改显示数据2022-07-08 + showDate(){ + if (this.year % 4 == 0 && this.year % 100 != 0 || this.year % 400 == 0) { + if(this.month === 2){ + this.days = [] + for (let i = 1; i <= 29; i++) { + this.days.push(i) + } + }else if(this.mouthArr1.includes(this.month)){ + this.days = [] + for (let i = 1; i <= 31; i++) { + this.days.push(i) + } + }else if(this.mouthArr2.includes(this.month)){ + this.days = [] + for (let i = 1; i <= 30; i++) { + this.days.push(i) + } + } + } else { + if(this.month === 2){ + this.days = [] + for (let i = 1; i <= 28; i++) { + this.days.push(i) + } + }else if(this.mouthArr1.includes(this.month)){ + this.days = [] + for (let i = 1; i <= 31; i++) { + this.days.push(i) + } + }else if(this.mouthArr2.includes(this.month)){ + this.days = [] + for (let i = 1; i <= 30; i++) { + this.days.push(i) + } + } + } + } //showDate + } }