国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue中UI組件庫之Vuex與虛擬服務器初識

2024-05-06 15:39:44
字體:
來源:轉載
供稿:網友

一、日歷組件

new Date()的月份是從0開始的。

下面表達式是:2018年6月1日new Date(2018, 5, 1);下面表達式是:2018年5月1日new Date(2018, 4, 1);或new Date(2018, 5-1, 1);下面表達式是:2018年5月31日(得到上個月的最后一天)new Date(2018, 5 , 0);日的參數可以是0,也可以是負數,表示上個月底的那一天。下面表達式是:2018年7月01日new Date(2018, 5, 31);

lApp.vue父組件:

<template> <div> <MonthView :year="year" :month="month"></MonthView> </div></template><script> import MonthView from "./components/MonthView.vue"; export default { data(){ return { year : 2018 , month : 8 , } }, components : { MonthView }, methods : { } }</script>

lMonthView.vue子組件

<template><div> 月視圖{{year}} {{month}} {{arr}} </div></template><script> export default { props : ["year" , "month"], computed : { arr(){ //計算日歷的數組:三要素 //本月1號星期幾 var this1DayWeek = new Date(this.year, this.month - 1, 1).getDay(); // 本月有幾天 var thisMonthDay = new Date(this.year, this.month, 0).getDate(); // 上月有多少天 var prevMonthDay = new Date(this.year, this.month - 1, 0).getDate(); console.log(benyue1haoxingqiji) console.log(benyueyoujitian) console.log(shangyueduoshaotian) } } }</script>

l顯示在頁面:

<template> <div> <table> <tr v-for="i in 6"> <td v-for="j in arr.slice((i-1) * 7, i * 7)">  {{j}} </td> </tr> </table> </div></template><script> export default { props:["year","month"], computed : { arr(){ var _arr = []; //存儲42天的數組 // 計算日歷的數組:三要素 //本月1號星期幾,根據星期幾得到上個月剩余天數 var this1DayWeek = new Date(this.year, this.month-1, 1).getDay(); //上個月有多少天 var prevMonthDay = new Date(this.year, this.month-1, 0).getDate(); //本月有幾天 var thisMonthDay = new Date(this.year, this.month, 0).getDate(); //用本月1號星期幾,推斷出上月的剩余天數 for(var i = 0; i < this1DayWeek;i++){  _arr.unshift(prevMonthDay - i) }  //循環本月天數(累加),從數組末尾插入 for(var i = 1; i <= thisMonthDay;i++){  _arr.push(i) } //補充下月的天數(滿42天為止) var i = 1; while(_arr.length != 42){  _arr.push(i++); }  return _arr; } } }</script>

l顯示農歷,安裝插件:

npm install solarlunar --save

<template> <div> <h1>月視圖 {{year}}年{{month}}月</h1> <table> <tr> <th>日</th> <th>一</th> <th>二</th> <th>三</th> <th>四</th> <th>五</th> <th>六</th> </tr> <tr v-for="i in 6"> <td v-for="j in arr.slice((i-1) * 7, i * 7)">  <p class="p1">{{j.d}}</p>  <p class="p2">{{j.n}}</p> </td> </tr> </table> </div></template><script> import solarLunar from 'solarLunar'; export default { props:["year","month"], computed : { arr(){ var _arr = []; //存儲42天的數組 // 計算日歷的數組:三要素 //本月1號星期幾,根據星期幾得到上個月剩余天數 var this1DayWeek = new Date(this.year, this.month-1, 1).getDay(); //上個月有多少天 var prevMonthDay = new Date(this.year, this.month-1, 0).getDate(); //本月有幾天 var thisMonthDay = new Date(this.year, this.month, 0).getDate(); //用本月1號星期幾,推斷出上月的剩余天數 for(var i = 0; i < this1DayWeek;i++){  _arr.unshift({  d: prevMonthDay - i,  n: solarLunar.solar2lunar(this.year, this.month-1, prevMonthDay - i).dayCn  }) }  //循環本月天數,累加,從數組末尾插入 for(var i = 1; i <= thisMonthDay;i++){  _arr.push({  d: i,  n: solarLunar.solar2lunar(this.year, this.month, i).dayCn  }) } //補充下個月的天數(滿42天為止) var i = 1; while(_arr.length != 42){  _arr.push({  d : i,  n : solarLunar.solar2lunar(this.year, this.month+1, i).dayCn  });  i++; } console.log(_arr) return _arr; } } }</script>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 雅江县| 喀喇| 丹凤县| 同江市| 洮南市| 阿合奇县| 中卫市| 荔浦县| 隆德县| 乌拉特后旗| 夹江县| 钟山县| 阳山县| 虎林市| 龙里县| 定日县| 镇坪县| 岳阳市| 黔江区| 正安县| 攀枝花市| 乌海市| 防城港市| 浮梁县| 民勤县| 台前县| 鹤峰县| 时尚| 高尔夫| 新平| 富蕴县| 铜鼓县| 五莲县| 诸城市| 蛟河市| 新河县| 东平县| 宿州市| 个旧市| 平顺县| 咸宁市|