el-element的DateTimePicker日期选择器设置能选择的范围为一年
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
<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 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)