ant design vue 日期選擇器只選擇年份


 

https://antdv.com/docs/vue/introduce-cn/

 

1
2
3
4
5
6
7
8
9
10
11
12
13
< a-form-model  :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
             < a-form-model-item  label="年度/季度" >
                 < a-date-picker
                 mode="year"
                 placeholder="請選擇年份"
                 format='YYYY'
                 v-model="form.yearQuarter" 
                 style="width:100%"
                 :open='yearShowOne' 
                 @openChange="openChangeOne"
                 @panelChange="panelChangeOne"/>
             </ a-form-model-item >
</ a-form-model >

  

年度打開關閉狀態,true為打開,false為關閉

yearShowOnefalse

 

1
2
3
4
5
6
7
8
9
10
11
12
13
methods: {
      // 彈出日歷和關閉日歷的回調
       openChangeOne(status) {
             if  (status){
                 this .yearShowOne =   true
             }
         },
      // 得到年份選擇器的值
      panelChangeOne(value) {
             this .form.yearQuarter = value;
             this .yearShowOne =  false ;
         }
}

     <a-date-picker
                  mode="year"
                  placeholder="請選擇年份"
                  format='YYYY'
                  v-model="searchForm.year"
                  style="width:100%"
                  :open='yearShowOne'
                  @openChange="openChangeOne"
                  @panelChange="panelChangeOne"/>
                  
                  yearShowOne: false,
                  
                  
                  openChangeOne(status) {
      if (status){
        this.yearShowOne =  true
      }
    },
    // 得到年份選擇器的值
    panelChangeOne(value) {
      let aa = value.toString();
      this.searchForm.year= aa.substring(11,15);
      this.yearShowOne = false;
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM