<el-date-picker type="daterange" v-model="dateRang" range-separtor="至" start- 
      placeholder="开始时间" end-placeholder="结束时间"  :picker-options="pickerOptions">
    </el-date-picker>

export default{

 data () {
    //不能在pickerOption通过this访问vue对象,因为this指向已经改变
     let that = this
   return{
     dateRang: [new Date(), ''],
      pickerOptions: {
        disabledDate (time) {
          let startyear = that.dateRang[0].getFullYear() - 1
          let endYear = that.dateRang[0].getFullYear() + 1

          let endDate = endYear + '-' + (that.dateRang[0].getMonth() + 1) + '-' +
                 that.dateRang[0].getDate()
          let startDate = startyear + '-' + (that.dateRang[0].getMonth() + 1) + '-' +
                  that.dateRang[0].getDate()
          let _endDate = new Date(endDate)
          let _startDate = new Date(startDate)
          //即大于开始时间小于结束时间
          return time.getTime() > _endDate.getTime() || time.getTime() < 
           _startDate.getTime()
 
                 },
        onPick ({minDate, maxDate}) {
           //重新设置开始时间
          that.dateRang[0] = minDate
          console.log(minDate)
        }

      }
   }
}
}

 

希望对大家有所帮助

 

 

GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐