最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實現(xiàn)周日歷切換效果

 更新時間:2022年04月18日 11:37:58   作者:weixin_44353999  
這篇文章主要為大家詳細介紹了vue實現(xiàn)周日歷切換效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)周日歷切換效果的具體代碼,供大家參考,具體內(nèi)容如下

廢話不多說,直接上干貨,需要的朋友自取

代碼:

<!DOCTYPE html>
<html lang="en">
<head>
? ? <meta charset="UTF-8">
? ? <meta http-equiv="X-UA-Compatible" content="IE=edge">
? ? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? ? <title>周日歷</title>
? ? <!-- 引入組件樣式 -->
? ? <link rel="stylesheet"  >
</head>
<body>
? ? <div id="app">
? ? ? ? <!-- 上面的日歷 -->
? ? ? ? <div class="calendar">
? ? ? ? ? ? <div class="arrow">
? ? ? ? ? ? ? ? <i class="el-icon-arrow-left" @click="arrow('left')"></i>
? ? ? ? ? ? ? ? <i class="el-icon-arrow-right" @click="arrow('right')"></i>
? ? ? ? ? ? </div>
? ? ? ? ? ? <el-calendar v-model="value" :range="dateRange"></el-calendar>
? ? ? ? </div>
? ? ? ? <!-- 下面的日歷 -->
? ? ? ? <div class="date">
? ? ? ? ? ? <div class="arrow0">
? ? ? ? ? ? ? ? <i class="el-icon-arrow-left" @click="weekPre"></i>
? ? ? ? ? ? ? ? <i class="el-icon-arrow-right" @click="weekNext"></i>
? ? ? ? ? ? </div>
? ? ? ? ? ? <!-- 年份 月份 -->
? ? ? ? ? ? <div class="month">
? ? ? ? ? ? ? ? <p>{{ currentYear }}年{{ currentMonth }}月</p>
? ? ? ? ? ? </div>
? ? ? ? ? ? <!-- 星期 -->
? ? ? ? ? ? <ul class="weekdays">
? ? ? ? ? ? ? ? <li>一</li>
? ? ? ? ? ? ? ? <li>二</li>
? ? ? ? ? ? ? ? <li>三</li>
? ? ? ? ? ? ? ? <li>四</li>
? ? ? ? ? ? ? ? <li>五</li>
? ? ? ? ? ? ? ? <li>六</li>
? ? ? ? ? ? ? ? <li>日</li>
? ? ? ? ? ? </ul>
? ? ? ? ? ? <!-- 日期 -->
? ? ? ? ? ? <ul class="days">
? ? ? ? ? ? ? ? <li @click="pick(day)" v-for="(day, index) in days" :key="index">
? ? ? ? ? ? ? ? ? ? <!--本月-->
? ? ? ? ? ? ? ? ? ? <span v-if="day.getMonth()+1 != currentMonth" class="other-month">{{ day.getDate() }}</span>
? ? ? ? ? ? ? ? ? ? <span v-else>
? ? ? ? ? ? ? ? ? ? <!--今天-->
? ? ? ? ? ? ? ? ? ? ? ? <span v-if="day.getFullYear() == new Date().getFullYear() && day.getMonth() == new Date().getMonth() && day.getDate() == new Date().getDate()" class="active">{{ day.getDate() }}</span>
? ? ? ? ? ? ? ? ? ? ? ? <span v-else>{{ day.getDate() }}</span>
? ? ? ? ? ? ? ? ? ? </span>
? ? ? ? ? ? ? ? </li>
? ? ? ? ? ? </ul>
? ? ? ? </div>
? ? </div>
</body>
<!-- 引入vue -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- 引入組件庫 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
? ? new Vue({
? ? el: '#app',
? ? data: function() {
? ? ? ? ? ? return {?
? ? ? ? ? ? ? ? // 上
? ? ? ? ? ? ? ? value: "",
? ? ? ? ? ? ? ? endDate: "",
? ? ? ? ? ? ? ? dateRange: [],
? ? ? ? ? ? ? ? dateNum: 0,
? ? ? ? ? ? ? ? // 下
? ? ? ? ? ? ? ? currentYear: "", ? // 年份
? ? ? ? ? ? ? ? currentMonth: "", ?// 月份
? ? ? ? ? ? ? ? currentDay: "", ? ?// 日期
? ? ? ? ? ? ? ? currentWeek: "", ? ?// 星期
? ? ? ? ? ? ? ? days: [],
? ? ? ? ? ? }
? ? ? ? },
? ? mounted () {
? ? ?
? ? },
? ? created () {
? ? ? ? // 上面的日歷
? ? ? ? this.dateList(this.dateNum);
? ? ? ? console.log(this.dateRange);
? ? ? ? // 下面的日歷
? ? ? ? this.initData();
? ? },
? ? methods: {
? ? ? ? // 上面的日歷
?
? ? ? ? // 獲取當前時間的周一
? ? ? ? getMonday(date) {
? ? ? ? ? ? var day = date.getDay();
? ? ? ? ? ? var deltaDay;
? ? ? ? ? ? if (day == 0) {
? ? ? ? ? ? ? ? deltaDay = 6;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? deltaDay = day - 1;
? ? ? ? ? ? }
? ? ? ? ? ? var monday = new Date(date.getTime() - deltaDay * 24 * 60 * 60 * 1000);
? ? ? ? ? ? monday.setHours(0);
? ? ? ? ? ? monday.setMinutes(0);
? ? ? ? ? ? monday.setSeconds(0);
? ? ? ? ? ? return monday; //返回選定時間的周一的0時0分0秒
? ? ? ? },
? ? ? ? getDateNew(time) {
? ? ? ? ? ? console.log(time);
? ? ? ? ? ? let times = new Date(time);
? ? ? ? ? ? let year = times.getFullYear();
? ? ? ? ? ? let month = times.getMonth() + 1 < 10 ? "0" + (times.getMonth() * 1 + 1) : times.getMonth() * 1 + 1;
? ? ? ? ? ? let day = times.getDate() < 10 ? "0" + times.getDate() * 1 : times.getDate() * 1;
? ? ? ? ? ? return year + "-" + month + "-" + day;
? ? ? ? },
? ? ? ? dateList(delta) {
? ? ? ? ? ? //將時間對象轉(zhuǎn)換為時間戳并加幾天后轉(zhuǎn)換為時間對象
? ? ? ? ? ? var DateNews = this.getMonday(
? ? ? ? ? ? ? ? new Date((new Date().getTime() / 1000 + 86400 * 7 * delta) * 1000)
? ? ? ? ? ? );
? ? ? ? ? ? let startDate = this.getDateNew(DateNews, delta);
? ? ? ? ? ? this.endDate = this.getDateNew(
? ? ? ? ? ? ? ? new Date((DateNews.getTime() / 1000 + 6 * 86400) * 1000)
? ? ? ? ? ? );
? ? ? ? ? ? this.dateRange = [startDate, this.endDate];
? ? ? ? },
? ? ? ? arrow(arrow) {
? ? ? ? ? ? if (arrow == "left") {
? ? ? ? ? ? ? ? this.dateNum--;
? ? ? ? ? ? ? ? this.dateList(this.dateNum);
? ? ? ? ? ? } else if (arrow == "right") {
? ? ? ? ? ? ? ? this.dateNum++;
? ? ? ? ? ? ? ? this.dateList(this.dateNum);
? ? ? ? ? ? }
? ? ? ? },
?
? ? ? ? // 下面的日歷
?
? ? ? ? formatDate (year, month, day) {
? ? ? ? ? ? const y = year
? ? ? ? ? ? let m = month
? ? ? ? ? ? if (m < 10) m = `0${m}`
? ? ? ? ? ? let d = day
? ? ? ? ? ? if (d < 10) d = `0$wppm3vysvbp`
? ? ? ? ? ? return `${y}-${m}-$wppm3vysvbp`
? ? ? ? },
? ? ? ? initData (cur) {
? ? ? ? ? ? let date = ''
? ? ? ? ? ? if (cur) {
? ? ? ? ? ? ? ? date = new Date(cur)
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? date = new Date()
? ? ? ? ? ? }
? ? ? ? ? ? this.currentDay = date.getDate() ? ? ? ? ?// 今日日期 幾號
? ? ? ? ? ? this.currentYear = date.getFullYear() ? ? ? // 當前年份
? ? ? ? ? ? this.currentMonth = date.getMonth() + 1 ? ?// 當前月份
? ? ? ? ? ? this.currentWeek = date.getDay() // 1...6,0 ? // 星期幾
? ? ? ? ? ? if (this.currentWeek === 0) {
? ? ? ? ? ? ? ? this.currentWeek = 7
? ? ? ? ? ? }
? ? ? ? ? ? const str = this.formatDate(this.currentYear, this.currentMonth, this.currentDay) // 今日日期 年-月-日
? ? ? ? ? ? this.days.length = 0
? ? ? ? ? ? // 今天是周日,放在第一行第7個位置,前面6個 這里默認顯示一周,如果需要顯示一個月,則第二個循環(huán)為 i<= 35- this.currentWeek
? ? ? ? ? ? /* eslint-disabled */
? ? ? ? ? ? for (let i = this.currentWeek - 1; i >= 0; i -= 1) {
? ? ? ? ? ? ? ? const d = new Date(str)
? ? ? ? ? ? ? ? d.setDate(d.getDate() - i)
? ? ? ? ? ? ? ? // console.log(y:" + d.getDate())
? ? ? ? ? ? ? ? this.days.push(d)
? ? ? ? ? ? }
? ? ? ? ? ? for (let i = 1; i <= 7 - this.currentWeek; i += 1) {
? ? ? ? ? ? ? ? const d = new Date(str)
? ? ? ? ? ? ? ? d.setDate(d.getDate() + i)
? ? ? ? ? ? ? ? this.days.push(d)
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? // ?上個星期
? ? ? ? weekPre () {
? ? ? ? ? ? const d = this.days[0] ? ?// 如果當期日期是7號或者小于7號
? ? ? ? ? ? d.setDate(d.getDate() - 7)
? ? ? ? ? ? this.initData(d)
? ? ? ? },
? ? ? ? // ?下個星期
? ? ? ? weekNext () {
? ? ? ? ? ? const d = this.days[6] ? ?// 如果當期日期是7號或者小于7號
? ? ? ? ? ? d.setDate(d.getDate() + 7)
? ? ? ? ? ? this.initData(d)
? ? ? ? },
? ? ? ? // 上一個月 ? 傳入當前年份和月份
? ? ? ? pickPre (year, month) {
? ? ? ? ? ? const d = new Date(this.formatDate(year, month, 1))
? ? ? ? ? ? d.setDate(0)
? ? ? ? ? ? this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
? ? ? ? },
? ? ? ? // 下一個月 ? 傳入當前年份和月份
? ? ? ? pickNext (year, month) {
? ? ? ? ? ? const d = new Date(this.formatDate(year, month, 1))
? ? ? ? ? ? d.setDate(35)
? ? ? ? ? ? this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
? ? ? ? },
? ? ? ? // 當前選擇日期
? ? ? ? pick (date) {
? ? ? ? ? ? alert(this.formatDate(date.getFullYear(), date.getMonth() + 1, date.getDate()))
? ? ? ? },
? ? },
}) ? ?
</script>
<style lang="scss">
? ? #app {
? ? ? ? width: 40%;
? ? ? ? margin: auto;
? ? }
? ? ul {
? ? ? ? padding: 0;
? ? }
? ? li {
? ? ? ? list-style-type: none;
? ? }
? ? /* 上面的日歷 */
? ? .calendar {
? ? ? ? position: relative;
? ? ? ? width: 100%;
? ? ? ? background: #fff;
? ? ? ? margin-top: 20px;
? ? ? ? margin-left: 20px;
? ? }
? ? .el-calendar__header {
? ? ? ? display: block;
? ? }
? ? .el-calendar-table .el-calendar-day {
? ? ? ? height: auto;
? ? ? ? text-align: center;
? ? }
? ? .el-calendar-table td.is-selected {
? ? ? ? background-color: #24b18d;
? ? ? ? color: #fff;
? ? }
? ? .el-calendar-table .el-calendar-day:hover {
? ? ? ? background-color: #24b18d;
? ? ? ? color: #fff;
? ? }
? ? .el-calendar-table {
? ? ? ? border-bottom: 1px solid #e4e4e4;
? ? ? ? padding-bottom: 15px;
? ? }
? ? .el-calendar-table .next {
? ? ? ? color: rgb(143, 143, 143);
? ? }
? ? .el-calendar__title,.el-calendar__button-group {
? ? ? ? text-align: center;
? ? }
? ? .arrow {
? ? ? ? width: 100%;
? ? ? ? max-height: 46px;
? ? ? ? position: absolute;
? ? ? ? top: 15px;
? ? ? ? text-align: center;
? ? }
? ? .arrow i {
? ? ? ? font-size: 20px;
? ? ? ? cursor: pointer;
? ? }
? ? .arrow i:nth-child(1) {
? ? ? ? margin-right: 10%;
? ? ? ? text-align: left;
? ? }
? ? .arrow i:nth-child(2) {
? ? ? ? margin-left: 10%;
? ? ? ? text-align: right;
? ? }
?
? ? /* 下面的日歷 */
? ? .date {
? ? ? ? position: relative;
? ? ? ? margin-top: 20px;
? ? ? ? padding: 10px 20px;
? ? ? ? background-color: #D3D3D3;
? ? }
? ? .arrow0 {
? ? ? ? width: 100%;
? ? ? ? max-height: 46px;
? ? ? ? position: absolute;
? ? ? ? top: 27px;
? ? ? ? left: 0px;
? ? ? ? text-align: center;
? ? }
? ? .arrow0 i {
? ? ? ? font-size: 20px;
? ? ? ? cursor: pointer;
? ? }
? ? .arrow0 i:nth-child(1) {
? ? ? ? margin-right: 10%;
? ? ? ? text-align: left;
? ? }
? ? .arrow0 i:nth-child(2) {
? ? ? ? margin-left: 10%;
? ? ? ? text-align: right;
? ? }
? ? .month {
? ? ? ? text-align: center;
? ? } ?
? ? .weekdays {
? ? ? ? display: flex;
? ? }?
? ? .weekdays li {
? ? ? ? flex: 1;
? ? ? ? text-align: center;
? ? }?
? ? .days {
? ? ? ? display: flex;
? ? }?
? ? .days li {
? ? ? ? flex: 1;
? ? ? ? text-align: center;
? ? ? ? cursor: pointer;
? ? }?
? ? .days li span {
? ? ? ? display: inline-block;
? ? ? ? width: 22px;
? ? ? ? height: 22px;
? ? }
? ? .days li span:hover {
? ? ? ? color: #fff;
? ? ? ? background-color: #409EFF;
? ? ? ? border-radius: 50%;
? ? }
? ? .active {
? ? ? ? display: inline-block;
? ? ? ? color: #fff;
? ? ? ? border-radius: 50%;
? ? ? ? background-color: #fa6854!important;
? ? }?
? ? .other-month {
? ? ? ? color: #e4393c;
? ? } ??
</style>
</html>

第二種日歷的實現(xiàn)方式

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Vite的常見配置選項詳細說明

    Vite的常見配置選項詳細說明

    相信大部分兄弟都體驗過Vite了,都知道它很快,在學習的時候,官網(wǎng)上的各種配置也是看的眼花繚亂,不知道哪些是必要掌握的,下面這篇文章主要給大家介紹了關于Vite常見配置選項的相關資料,需要的朋友可以參考下
    2024-09-09
  • Vue使用Axios進行跨域請求的方法詳解

    Vue使用Axios進行跨域請求的方法詳解

    在開發(fā)現(xiàn)代?Web?應用時,前端和后端通常分離部署在不同的服務器上,這就會引發(fā)跨域請求問題,所以本文將詳細介紹如何在?Vue?項目中使用?Axios?發(fā)起跨域請求時解決跨域問題的相關資料,需要的朋友可以參考下
    2024-09-09
  • vue3配置router路由并實現(xiàn)頁面跳轉(zhuǎn)功能

    vue3配置router路由并實現(xiàn)頁面跳轉(zhuǎn)功能

    這篇文章主要介紹了vue3配置router路由并實現(xiàn)頁面跳轉(zhuǎn),本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • Element-Plus之el-col與el-row快速布局

    Element-Plus之el-col與el-row快速布局

    el-col是el-row的子元素,下面這篇文章主要給大家介紹了關于Element-Plus之el-col與el-row快速布局的相關資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-09-09
  • 通過vue手動封裝on、emit、off的代碼詳解

    通過vue手動封裝on、emit、off的代碼詳解

    這篇文章主要介紹了通過vue手動封裝on,emit,off的代碼詳解,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-05-05
  • Vue3中SetUp函數(shù)的參數(shù)props、context詳解

    Vue3中SetUp函數(shù)的參數(shù)props、context詳解

    我們知道setup函數(shù)是組合API的核心入口函數(shù),下面這篇文章主要給大家介紹了關于Vue3中SetUp函數(shù)的參數(shù)props、context的相關資料,需要的朋友可以參考下
    2021-07-07
  • 徹底搞懂Transition內(nèi)置組件

    徹底搞懂Transition內(nèi)置組件

    這篇文章主要為大家介紹了Transition內(nèi)置組件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-07-07
  • vue3.0+ts引入詳細步驟以及語法校驗報錯問題解決辦法

    vue3.0+ts引入詳細步驟以及語法校驗報錯問題解決辦法

    Vue?3.0是一個非常流行的JavaScript框架,不僅易于學習和使用,而且可以與許多UI框架集成,下面這篇文章主要給大家介紹了關于vue3.0+ts引入詳細步驟以及語法校驗報錯問題的解決辦法,需要的朋友可以參考下
    2024-01-01
  • 關于Element-UI中slot的用法及說明

    關于Element-UI中slot的用法及說明

    這篇文章主要介紹了關于Element-UI中slot的用法及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue中 axios delete請求參數(shù)操作

    Vue中 axios delete請求參數(shù)操作

    這篇文章主要介紹了Vue中 axios delete請求參數(shù)操作,具有很好的參考價值,希望對大家有所 幫助。一起跟隨小編過來看看吧
    2020-08-08

最新評論

西昌市| 长治县| 德令哈市| 磴口县| 遂平县| 孝感市| 抚州市| 马山县| 尉犁县| 互助| 关岭| 都兰县| 郸城县| 宁安市| 那曲县| 浦北县| 城市| 岳池县| 南城县| 乌鲁木齐县| 西乡县| 岳池县| 广西| 成武县| 多伦县| 建始县| 依安县| 利川市| 广汉市| 江山市| 房产| 丹阳市| 禄丰县| 集贤县| 定安县| 丁青县| 长治县| 铁岭县| 高淳县| 佳木斯市| 禹州市|