基于vue2.0+vuex的日期選擇組件功能實現(xiàn)
calendar vue日期選擇組件
一個選擇日期的vue組件
基于vue2.0 + vuex
原本是想找這樣的一個組件的,查看了vuex后,發(fā)現(xiàn)vuex的寫法還不是基于2.0的,所以就自己動手做了
demo展示&&項目中的使用
目錄結(jié)構(gòu)
demo 用vue-cli 的webpack-simple構(gòu)建的
calendar |--dist build生成的目錄 |--doc 展示圖片 |--src |--assets 資源 |--components |--calendar 日期組件 |--dateScroll 滾動的子組件 |--css |store vuex目錄 |--modules |--calendar |--mutation 組件的一些狀態(tài) |--store |App.vue 入口 |main.js
組件使用
組件可以傳入一個年份的范圍,startTime 和 endTime 都是數(shù)字, 默認是1900 - 2050
觸發(fā)組件 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 () { //觸發(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>
運行
# install dependencies npm install # serve with hot reload at localhost:8081 npm run dev # build for production with minification npm run build
版本
1.0.0 vue日期組件
demo地址:vue-calendar_jb51.rar
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
electron-vue?項目添加啟動loading動畫的實現(xiàn)思路
electron-vue腳手架搭建的項目,在開發(fā)階段可能你注意不到項目啟動慢的問題,但是在build?生成的exe可執(zhí)行文件,啟動后,要反應很久才能進入到app.vue?中加載的頁面,體驗性很差,本文給大家介紹electron?vue啟動動畫效果的實例代碼,感興趣的朋友一起看看吧2022-01-01vue短信驗證性能優(yōu)化如何寫入localstorage中
這篇文章主要介紹了vue短信驗證性能優(yōu)化寫入localstorage中的方法,解決這個問題需要把時間都寫到localstorage里面去,具體解決方法大家參考下本文2018-04-04