基于vue2.0+vuex的日期選擇組件功能實(shí)現(xiàn)
calendar vue日期選擇組件
一個(gè)選擇日期的vue組件
基于vue2.0 + vuex
原本是想找這樣的一個(gè)組件的,查看了vuex后,發(fā)現(xiàn)vuex的寫法還不是基于2.0的,所以就自己動(dòng)手做了
demo展示&&項(xiàng)目中的使用
目錄結(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
版本
1.0.0 vue日期組件
demo地址:vue-calendar_jb51.rar
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 解決antd日期選擇組件,添加value就無法點(diǎn)擊下一年和下一月問題
- vue左右滑動(dòng)選擇日期組件封裝的方法
- Vue下拉選擇框Select組件使用詳解(二)
- Vue下拉選擇框Select組件使用詳解(一)
- 詳解vue移動(dòng)端日期選擇組件
- vue.js實(shí)現(xiàn)仿原生ios時(shí)間選擇組件實(shí)例代碼
- Vue無限滑動(dòng)周選擇日期的組件的示例代碼
- 基于Vue組件化的日期聯(lián)動(dòng)選擇器功能的實(shí)現(xiàn)代碼
- vue-calendar-component 封裝多日期選擇組件的實(shí)例代碼
- Ant Design封裝年份選擇組件的方法
相關(guān)文章
記錄--使用el-time-picker默認(rèn)值遇到的問題
這篇文章主要介紹了記錄--使用el-time-picker默認(rèn)值遇到的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09electron-vue?項(xiàng)目添加啟動(dòng)loading動(dòng)畫的實(shí)現(xiàn)思路
electron-vue腳手架搭建的項(xiàng)目,在開發(fā)階段可能你注意不到項(xiàng)目啟動(dòng)慢的問題,但是在build?生成的exe可執(zhí)行文件,啟動(dòng)后,要反應(yīng)很久才能進(jìn)入到app.vue?中加載的頁面,體驗(yàn)性很差,本文給大家介紹electron?vue啟動(dòng)動(dòng)畫效果的實(shí)例代碼,感興趣的朋友一起看看吧2022-01-01手把手教你Vue3實(shí)現(xiàn)路由跳轉(zhuǎn)
Vue Router是Vue.js的官方路由器,它與Vue.js核心深度集成,使使用Vue.js構(gòu)建單頁應(yīng)用程序變得輕而易舉,下面這篇文章主要給大家介紹了關(guān)于Vue3實(shí)現(xiàn)路由跳轉(zhuǎn)的相關(guān)資料,需要的朋友可以參考下2022-08-08vue短信驗(yàn)證性能優(yōu)化如何寫入localstorage中
這篇文章主要介紹了vue短信驗(yàn)證性能優(yōu)化寫入localstorage中的方法,解決這個(gè)問題需要把時(shí)間都寫到localstorage里面去,具體解決方法大家參考下本文2018-04-04