溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

vue怎么實(shí)現(xiàn)日期選擇組件功能

發(fā)布時(shí)間:2022-11-03 10:00:34 來源:億速云 閱讀:124 作者:iii 欄目:開發(fā)技術(shù)

這篇文章主要講解了“vue怎么實(shí)現(xiàn)日期選擇組件功能”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“vue怎么實(shí)現(xiàn)日期選擇組件功能”吧!

目錄結(jié)構(gòu)

demo 用vue-cli 的webpack-simple構(gòu)建的

calendar
 |--dist build生成的目錄
 |--doc  展示圖片
 |--src
   |--assets 資源
   |--components
     |--calendar  日期組件
     |--dateScroll 滾動(dòng)的子組件
   |--css
   |store  vuex目錄
     |--modules
       |--calendar  
     |--mutation   組件的一些狀態(tài)
     |--store
   |App.vue  入口
   |main.js

組件使用

組件可以傳入一個(gè)年份的范圍,startTime 和 endTime 都是數(shù)字, 默認(rèn)是1900 - 2050

觸發(fā)組件 this.$store.dispatch('calendarStatus',true)

  <template>
   <div id="app">
    <p @click = "setDate">點(diǎn)擊設(shè)置日期</p>
     <!--顯示返回的日期-->
    <p>{{date}}</p>
     <!--組件-->
    <com-calendar :style = "calendar" :startTime = "start" :endTime="end"></com-calendar>
      <!--遮罩-->
    <div v-show = "mark" class="mark" @touchmove.stop.prevent ="" @touchstart.stop.prevent ="" @touchend.stop.prevent =""></div>

   </div>
  </template>

  <script>
   require('./css/style.scss');
  import calendar from './components/calendar';
  export default {
   name: 'app',
   data () {
    return {
     //選擇日期的開始返回,默認(rèn)是1900 - 2050
      start:1950,
      end:2030
    }
   },
   components:{
    comCalendar:calendar
   },
   methods:{
    setDate:function () {
     //觸發(fā)日期組件
     this.$store.dispatch('calendarStatus',true);
    }
   },
    computed:{
     //遮罩狀態(tài)
     mark:function () {
      return this.$store.getters.markStatus
     },
     //組件狀態(tài)
     calendar:function () {
      return this.$store.getters.getCalendarStatus?{ display:'block'}:{ display:'none'};
     },
     //返回的日期
     date:function () {
      return this.$store.getters.getCalendarDate;
     }

    }

  }
  </script>

運(yùn)行

# install dependencies
npm install

# serve with hot reload at localhost:8081
npm run dev

# build for production with minification
npm run build

Vue的優(yōu)點(diǎn)

Vue具體輕量級(jí)框架、簡單易學(xué)、雙向數(shù)據(jù)綁定、組件化、數(shù)據(jù)和結(jié)構(gòu)的分離、虛擬DOM、運(yùn)行速度快等優(yōu)勢(shì),Vue中頁面使用的是局部刷新,不用每次跳轉(zhuǎn)頁面都要請(qǐng)求所有數(shù)據(jù)和dom,可以大大提升訪問速度和用戶體驗(yàn)。

感謝各位的閱讀,以上就是“vue怎么實(shí)現(xiàn)日期選擇組件功能”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)vue怎么實(shí)現(xiàn)日期選擇組件功能這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

vue
AI