如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能

這篇文章主要為大家展示了“如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能”這篇文章吧。

建陽(yáng)網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,建陽(yáng)網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為建陽(yáng)超過(guò)千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營(yíng)銷網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的建陽(yáng)做網(wǎng)站的公司定做!

calendar vue日期選擇組件

一個(gè)選擇日期的vue組件

基于vue2.0 + vuex

原本是想找這樣的一個(gè)組件的,查看了vuex后,發(fā)現(xiàn)vuex的寫法還不是基于2.0的,所以就自己動(dòng)手做了

demo展示&&項(xiàng)目中的使用

如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能

如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能

目錄結(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 {
     //選擇日期的開(kāi)始返回,默認(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

以上是“如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站名稱:如何實(shí)現(xiàn)基于vue2.0+vuex的日期選擇組件功能
文章分享:http://muchs.cn/article38/jcpgsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、面包屑導(dǎo)航、網(wǎng)站制作、微信公眾號(hào)App設(shè)計(jì)、用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站