亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue通過v-for實現(xiàn)年份自動遞增

 更新時間:2022年09月01日 10:38:13   作者:小貓喵了個咪噠~  
這篇文章主要為大家詳細介紹了Vue通過v-for實現(xiàn)年份自動遞增,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Vue篩選時通過 v-for 實現(xiàn)年份自動遞增,供大家參考,具體內容如下

在做數(shù)據篩選時一般會用到Element-UI組件的方式進行編寫,偶爾也會用平鋪的方式對時間進行篩選(類似購物網站的篩選功能),并實現(xiàn)年份的自動增加

以下是用平鋪的方式對數(shù)據篩選 (已省略表格)
部分解釋的可能不太清楚,但也可以實現(xiàn)的

效果圖如下

當年份為2022時

當年份為2030時

代碼如下

<template>
? ? <div>
? ? ? ? <div class="block">
? ? ? ? ? ? <span>年份
? ? ? ? ? ? ? ? <el-button class="btnclick" v-for="(item, index) in yearlist" :key="index" size="mini"
? ? ? ? ? ? ? ? ? ? @click="handleFilterYear(item)" round>
? ? ? ? ? ? ? ? ? ? {{ item.DText }}
? ? ? ? ? ? ? ? </el-button>
? ? ? ? ? ? </span>
? ? ? ? </div>
? ? ? ? <div class="block">
? ? ? ? ? ? <span>月份
? ? ? ? ? ? ? ? <el-button class="btnclick" v-for="(item, index) in mouthlist" :key="index" size="mini"
? ? ? ? ? ? ? ? ? ? @click="handleFilterMouth(item)" round>
? ? ? ? ? ? ? ? ? ? {{ item.DText }}
? ? ? ? ? ? ? ? </el-button>
? ? ? ? ? ? ? ? <el-button class="btnclick" type="primary" size="mini" @click="searchClearFun()">重置
? ? ? ? ? ? ? ? </el-button>
? ? ? ? ? ? </span>
? ? ? ? </div>
? ? </div>
</template>?
<script>
export default {
? ? data() {
? ? ? ? return {
? ? ? ? ? ? serch1: new Date().getFullYear(), //年 ?默認傳當年年份
? ? ? ? ? ? serch2: '', //月
? ? ? ? ? ? yearlist: [{ //年
? ? ? ? ? ? ? ? Index: 0,
? ? ? ? ? ? ? ? DText: '2022'
? ? ? ? ? ? }],
? ? ? ? ? ? mouthlist: [{ //月
? ? ? ? ? ? ? ? Index: 0,
? ? ? ? ? ? ? ? DText: '1'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 1,
? ? ? ? ? ? ? ? DText: '2'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 2,
? ? ? ? ? ? ? ? DText: '3'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 3,
? ? ? ? ? ? ? ? DText: '4'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 4,
? ? ? ? ? ? ? ? DText: '5'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 5,
? ? ? ? ? ? ? ? DText: '6'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 6,
? ? ? ? ? ? ? ? DText: '7'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 7,
? ? ? ? ? ? ? ? DText: '8'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 8,
? ? ? ? ? ? ? ? DText: '9'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 9,
? ? ? ? ? ? ? ? DText: '10'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 10,
? ? ? ? ? ? ? ? DText: '11'
? ? ? ? ? ? }, {
? ? ? ? ? ? ? ? Index: 11,
? ? ? ? ? ? ? ? DText: '12'
? ? ? ? ? ? }]
? ? ? ? }
? ? }
? ? mounted() {
? ? ? ? // 定義年份列表 ,默認為今年 2022 ,當2023時會自動顯示 2022 ?2023 ?.....
? ? ? ? var nowYearList = new Date().getFullYear();
? ? ? ? var nowYearLength = parseInt(nowYearList) - 2022;
? ? ? ? if (nowYearLength > 0) {
? ? ? ? ? ? if (nowYearLength < 2) {
? ? ? ? ? ? ? ? this.yearlist = [{
? ? ? ? ? ? ? ? ? ? Index: 0,
? ? ? ? ? ? ? ? ? ? DText: '2022'
? ? ? ? ? ? ? ? }]
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? var yearListArr = [];
? ? ? ? ? ? ? ? for (var i = 0; i <= nowYearLength; i++) {
? ? ? ? ? ? ? ? ? ? var yearObj = {};
? ? ? ? ? ? ? ? ? ? yearObj.Index = i;
? ? ? ? ? ? ? ? ? ? yearObj.DText = parseInt(2022 + i);
? ? ? ? ? ? ? ? ? ? yearListArr.push(yearObj)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.yearlist = yearListArr
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? methods: {
? ? ? ? //年份篩選
? ? ? ? handleFilterYear(item) {
? ? ? ? ? ? this.serch1 = item.DText
? ? ? ? ? ? this.dataCount(); ? //調用數(shù)據列表的方法
? ? ? ? },
? ? ? ? // 月份篩選
? ? ? ? handleFilterMouth(item) {
? ? ? ? ? ? this.serch2 = item.DText
? ? ? ? ? ? this.dataCount(); ?//調用數(shù)據列表的方法
? ? ? ? },
? ? ? ? //清空查詢
? ? ? ? searchClearFun() {
? ? ? ? ? ? this.serch1 = '' ?//清空年份
? ? ? ? ? ? this.serch2 = '' ?//清空月份
? ? ? ? ? ? this.dataCount() //調用數(shù)據列表的方法
? ? ? ? },
? ? }
}
</script>
<style scoped lang="scss">
? ?.block span {
? ? ? font-size: 15px;
? ? ? display: block;
? ? ? text-align: left;
? ? ? padding: 20px 0 0 20px;
? ? }
</style>

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

相關文章

  • 在vscode里使用.vue代碼模板的方法

    在vscode里使用.vue代碼模板的方法

    本篇文章主要介紹了在vscode里使用.vue代碼模板的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • vue-cli初始化項目中使用less的方法

    vue-cli初始化項目中使用less的方法

    vue-cli 是 vue.js 的腳手架工具,可以幫助我們編寫基礎代碼、快速搭建開發(fā)環(huán)境。下面這篇文章主要給大家介紹了關于vue-cli初始化項目中使用less的相關資料,需要的朋友可以參考借鑒,下面隨著小編來一起看看吧
    2018-08-08
  • Vue自定義指令獲取不到參數(shù)的原因及解決

    Vue自定義指令獲取不到參數(shù)的原因及解決

    這篇文章主要介紹了Vue自定義指令獲取不到參數(shù)的原因及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue開發(fā)中常見的套路和技巧總結

    Vue開發(fā)中常見的套路和技巧總結

    這篇文章主要給大家介紹了關于Vue開發(fā)中常見的套路和技巧的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • vue 單元測試的推薦插件和使用示例

    vue 單元測試的推薦插件和使用示例

    單元測試是軟件開發(fā)非?;A的一部分。單元測試會封閉執(zhí)行最小化單元的代碼,使得添加新功能和追蹤問題更容易。Vue 的單文件組件使得為組件撰寫隔離的單元測試這件事更加直接。它會讓你更有信心地開發(fā)新特性而不破壞現(xiàn)有的實現(xiàn),并幫助其他開發(fā)者理解你的組件的作用。
    2021-06-06
  • Vue通過路由實現(xiàn)頁面間參數(shù)的傳遞

    Vue通過路由實現(xiàn)頁面間參數(shù)的傳遞

    這篇文章主要介紹了Vue通過路由實現(xiàn)頁面間參數(shù)的傳遞,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • vue基礎之事件v-onclick=

    vue基礎之事件v-onclick="函數(shù)"用法示例

    這篇文章主要介紹了vue基礎之事件v-onclick="函數(shù)"用法,結合實例形式分析了vue.js事件v-on:click="函數(shù)"的data數(shù)據添加、點擊響應、以及留言本功能相關操作技巧,需要的朋友可以參考下
    2019-03-03
  • vue中bus的使用及踩坑解決

    vue中bus的使用及踩坑解決

    這篇文章主要為大家詳細介紹了vue中bus的相關使用以及涉及到的問題與解決,文中的示例代碼簡潔易懂,感興趣的小伙伴可以跟隨小編一起了解一下
    2023-08-08
  • Vite內網ip訪問2種配置方式

    Vite內網ip訪問2種配置方式

    這篇文章主要給大家介紹了關于Vite內網ip訪問的2種配置方式,文中通過實例代碼介紹的非常詳細,對大家學習或者使用Vite具有一定的參考學習價值,需要的朋友可以參考下
    2023-07-07
  • vue計算屬性computed--getter和setter用法

    vue計算屬性computed--getter和setter用法

    這篇文章主要介紹了vue計算屬性computed--getter和setter用法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01

最新評論