vue年季度月联动筛选(el-cascader实现)

 

 默认显示当年当季当月

  <label class="font-weight">时间范围</label>&nbsp;&nbsp;

                 <el-cascader
              placeholder="请选择"
              :options="timeOption"
              filterable
              clearable
              change-on-select
              v-model="timeRange"
              :props="{

                emitPath: true
              }"
               @change="getPage()"
            ></el-cascader>

 

 timeRange:'',//默认当年当季当月
      timeOption:[{
          value: '2023年',
          label: '2023年',
          children: [{
            value: '第一季度',
            label: '第一季度',
             children: [{
            value: '1月',
            label: '1月'
          },{
            value: '2月',
            label: '2月'
          },{
            value: '3月',
            label: '3月'
          }]
          }, {
            value: '第二季度',
            label: '第二季度',
             children: [{
            value: '4月',
            label: '4月'
          },{
            value: '5月',
            label: '5月'
          },{
            value: '6月',
            label: '6月'
          }]
          },  {
            value: '第三季度',
            label: '第三季度',
             children: [{
            value: '7月',
            label: '7月'
          },{
            value: '8月',
            label: '8月'
          },{
            value: '9月',
            label: '9月'
          }]
          }, {
            value: '第四季度',
            label: '第四季度',
             children: [{
            value: '10月',
            label: '10月'
          },{
            value: '11月',
            label: '11月'
          },{
            value: '12月',
            label: '12月'
          }]
          }]
        }],

  created(){
this.getNowTimeRange();
  },

      getNowTimeRange() {
        //获取当前年
const year=new Date().getFullYear()+'年';
// 获取当前季度:
      var currMonth = new Date().getMonth() + 1;
      var currQuarter = Math.floor(
        currMonth % 3 == 0 ? currMonth / 3 : currMonth / 3 + 1
      );
      const info = {
        1: "第一季度",
        2: "第二季度",
        3: "第三季度",
        4: "第四季度"
      };
      const quarter = info[currQuarter];

      //获取当前月
      const monthNum =new Date().getMonth() + 1;
      const nowMonth= monthNum+'月';
      this.timeRange=[year,quarter,nowMonth];

      console.log("%c Line:528 🍿", "color:#3f7cff",this.timeRange);
    },

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue3是一种流行的JavaScript框架,而el-cascader是一个基于Vue的级联选择器组件。结合Vue3和el-cascader可以很方便地实现省市区三级联动功能。 首先,你需要在项目中安装Vue3和el-cascader。可以使用npm或者yarn进行安装。 接下来,在你的Vue组件中引入el-cascader组件,并在data中定义一个数组用于存储省市区数据。你可以通过接口请求或者本地数据来获取省市区数据。 然后,在模板中使用el-cascader组件,并将省市区数据绑定到el-cascader的options属性上。通过设置props属性,你可以指定级联选择器的显示文本和值的字段名。 最后,你需要监听el-cascader的change事件,在事件处理函数中获取选择的省市区数值,并进行相应的处理。 下面是一个简单的示例代码: ``` <template> <div> <el-cascader v-model="selectedValues" :options="options" :props="props" @change="handleCascaderChange" ></el-cascader> </div> </template> <script> import { ref } from 'vue'; export default { data() { return { selectedValues: [], // 存储选择的省市区数值 options: [], // 省市区数据 props: { value: 'value', // 值字段名 label: 'label', // 显示文本字段名 children: 'children' // 子级字段名 } }; }, mounted() { // 获取省市区数据,可以通过接口请求或者本地数据获取 this.options = [ { value: '1', label: '省份1', children: [ { value: '11', label: '城市1', children: [ { value: '111', label: '区域1' }, { value: '112', label: '区域2' } ] }, { value: '12', label: '城市2', children: [ { value: '121', label: '区域1' }, { value: '122', label: '区域2' } ] } ] }, // 其他省市区数据... ]; }, methods: { handleCascaderChange(value) { // 处理选择的省市区数值 console.log(value); } } }; </script> ``` 这样,你就可以实现省市区三级联动功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JianZhen✓

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值