项目场景:
下拉菜单显示年份选项(月份也适用)
前段语言Vue
问题描述
在列表的搜索栏常常需要提供年份、月份选择,此文记录一种简单的年份下拉菜单的展示方式:
<el-form-item label="年份" prop="year"><el-select v-model="queryParams.year" placeholder="请选择年份" @change="handleQuery" filterable clearable size="small" style="width:115px"><el-optionv-for="item in yearsList":key="item.label":label="item.label":value="item.value"></el-option></el-select></el-form-item>
export default {data() {return {// 年份yearsList:[],};},created() {this.initYears();},methods: {,/** 设置日期列表 */initYears(){let myDate = new Date;let year = myDate.getFullYear();//获取当前年this.initSelectYear(year)},initSelectYear(year) {this.yearsList = [];let count = year - 2019 + 1;for (let i = 0; i < count; i++) {this.yearsList.push({value: (year - i), label: (year - i) + ""});}}}
}