calendar vue日期選擇組件
一個選擇日期的vue組件
基于vue2.0 + vuex
原本是想找這樣的一個組件的,查看了vuex后,發現vuex的寫法還不是基于2.0的,所以就自己動手做了
demo展示&&項目中的使用


目錄結構
demo 用vue-cli 的webpack-simple構建的
calendar |--dist build生成的目錄 |--doc 展示圖片 |--src |--assets 資源 |--components |--calendar 日期組件 |--dateScroll 滾動的子組件 |--css |store vuex目錄 |--modules |--calendar |--mutation 組件的一些狀態 |--store |App.vue 入口 |main.js
組件使用
組件可以傳入一個年份的范圍,startTime 和 endTime 都是數字, 默認是1900 - 2050
觸發組件 this.$store.dispatch('calendarStatus',true)
<template> <div id="app"> <p @click = "setDate">點擊設置日期</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 { //選擇日期的開始返回,默認是1900 - 2050 start:1950, end:2030 } }, components:{ comCalendar:calendar }, methods:{ setDate:function () { //觸發日期組件 this.$store.dispatch('calendarStatus',true); } }, computed:{ //遮罩狀態 mark:function () { return this.$store.getters.markStatus }, //組件狀態 calendar:function () { return this.$store.getters.getCalendarStatus?{ display:'block'}:{ display:'none'}; }, //返回的日期 date:function () { return this.$store.getters.getCalendarDate; } } } </script>運行
# install dependenciesnpm install# serve with hot reload at localhost:8081npm run dev# build for production with minificationnpm run build
版本
1.0.0 vue日期組件
demo地址:vue-calendar_jb51.rar
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答