欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

VUE實(shí)現(xiàn)移動(dòng)端列表篩選功能

 更新時(shí)間:2019年08月23日 14:00:53   作者:一生舍給一座山  
這篇文章主要介紹了VUE實(shí)現(xiàn)移動(dòng)端列表篩選功能,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

最近興趣所致,打算使用vant搭建一個(gè)webapp,由于需要使用列表篩選,沒有找到合適組件,于是寫了一個(gè)簡(jiǎn)單的功能,權(quán)當(dāng)記錄。

效果如下:

HTML:

<div class="filterbar">
   <div class="filterbar-title">
    <ul class="title-ul">
     <li
      :class="{'title-li':true, 'current': item.isShow}"
      v-for="(item, index) in barMenus"
      :key="index"
     >
      <span @click="handerClickMenu(item)">
       {{item.name}}
       <van-icon :name="item.isShow ? 'arrow-up' :'arrow-down'" />
      </span>
      <div class="filterbar-content" v-on:click.stop v-if="item.isShow">
       <ul class="content-ul">
        <li
         v-for="(child, number) in item.data"
         :key="number"
         :class="{'current': child.selected}"
         @click="handerClickContent(item, child)"
        >
         {{child.name}}
         <van-icon v-if="child.selected" name="success" />
        </li>
       </ul>
       <div class="button-div" v-if="item.multiple">
        <van-button plain type="default" @click="handerClear(item)">清空</van-button>
        <van-button type="info" @click="search">確定</van-button>
       </div>
      </div>
     </li>
    </ul>
   </div>
   <div class="bg-filterbar" v-if="isBgFilterbarShow" @click="handerClickMenu"></div>
  </div>

CSS:

.filterbar {
  position: fixed;
  z-index: 2;
  left: 0;
  top: 3.1em;
  width: 100%;
  background-color: #fff;
  height: 2em;

  .bg-filterbar {
   position: fixed;
   width: 100%;
   height: 100%;
   background-color: black;
   opacity: 0.2;
   z-index: 1;
   left: 0;
   top: 4.2em;
  }
  .filterbar-title {
   width: 100%;
   .title-ul {
    height: 1.4em;
    margin-bottom: 0.5em;
    border-bottom: 1px solid #eee;
   }
   ul .title-li {
    width: 24%;
    float: left;
    text-align: center;
    font-size: 0.9em;

    .filterbar-content {
     position: absolute;
     left: 0;
     width: 100%;
     padding: 0.5em;
     background-color: #fff;
     z-index: 2;
     top: 1.24em;
    }
    .content-ul li {
     text-align: left;
     color: #111;
     font-weight: 400;
     padding-left: 1.5em;
     padding-top: 0.7em;
    }
    .content-ul .current {
     color: #1989fa;
    }
   }
   ul .current {
    color: #1989fa;
    font-weight: 600;
   }
   ul:after {
    content: "";
    display: block;
    clear: both;
   }
   .content-ul .van-icon {
    float: right;
    margin-right: 2.5em;
   }
   ul .van-icon {
    vertical-align: middle;
   }
  }
  .button-div {
   margin-top: 1.5em;
   text-align: center;

   button {
    width: 48%;
    float: left;
   }
   .van-button {
    height: 3em;
    line-height: 3em;
    font-size: 1em;
    font-weight: 400;
   }
  }
 }

JS:

<script>
export default {
 data() {
  return {
   barMenus: [
    {
     name: "菜系",
     value: 1,
     isShow: false,
     multiple: true,
     data: [
      { name: "川菜", value: 1, selected: false },
      { name: "粵菜", value: 2, selected: false },
      { name: "湘菜", value: 3, selected: false },
      { name: "蘇菜", value: 4, selected: false },
      { name: "閩菜", value: 5, selected: false },
      { name: "徽菜", value: 6, selected: false },
      { name: "浙菜", value: 7, selected: false },
      { name: "魯菜", value: 8, selected: false }
     ]
    },
    {
     name: "口味",
     value: 2,
     isShow: false,
     multiple: true,
     data: [
      { name: "清淡", value: 1, selected: false },
      { name: "麻辣", value: 2, selected: false },
      { name: "養(yǎng)生", value: 3, selected: false }
     ]
    },
    {
     name: "適合人群",
     value: 3,
     isShow: false,
     multiple: true,
     data: [
      { name: "老人", value: 1, selected: false },
      { name: "嬰兒", value: 2, selected: false },
      { name: "小孩", value: 2, selected: false },
      { name: "病人", value: 2, selected: false }
     ]
    },
    {
     name: "排序",
     value: 4,
     isShow: false,
     multiple: false,
     data: [
      { name: "做過最多", value: 1, selected: false },
      { name: "點(diǎn)贊最多", value: 2, selected: false }
     ]
    }
   ]
  };
 },

 computed: {
  isBgFilterbarShow: {
   get() {
    let isBgShow = false;
    this.barMenus.forEach(function(currentValue, index, arr) {
     if (currentValue.isShow) {
      isBgShow = true;
     }
    });
    return isBgShow;
   }
  }
 },

 methods: {
  search() {
   this.handerClose();
  },

  handerClose() {
   this.barMenus.forEach(function(currentValue, index, arr) {
    currentValue.isShow = false;
   });
  },

  handerClickMenu(item) {
   if (!item) {
    return;
   }

   this.barMenus.forEach(function(currentValue, index, arr) {
    if (currentValue.value == item.value) {
     currentValue.isShow = !currentValue.isShow;
    } else {
     currentValue.isShow = false;
    }
   });
  },

  handerClickContent(item, child) {
   if (!item.multiple) {
    this.handerClear(item);
    this.handerClose(item);
   }

   child.selected = !child.selected;
  },

  handerClear(item) {
   item.data.forEach(function(currentValue, index, arr) {
    currentValue.selected = false;
   });
  }
 }
};
</script>

參數(shù)說明:

name:篩選項(xiàng)顯示名稱
value:篩選項(xiàng)code
isShow:是否顯示
multiple: 是否多選,為true時(shí)會(huì)有清空和確定功能按鈕
data: 篩選列表項(xiàng)

總結(jié)

以上所述是小編給大家介紹的VUE實(shí)現(xiàn)移動(dòng)端列表篩選功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • 解決vue-cli3 使用子目錄部署問題

    解決vue-cli3 使用子目錄部署問題

    這篇文章主要介紹了解決vue-cli3 使用子目錄部署問題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-07-07
  • vue.js入門教程之綁定class和style樣式

    vue.js入門教程之綁定class和style樣式

    小編之前介紹了通過vue.js計(jì)算屬性,不知道大家都學(xué)會(huì)了嗎。那這篇文章中我們將一起學(xué)習(xí)vue.js實(shí)現(xiàn)綁定class和style樣式,有需要的朋友們可以參考借鑒。
    2016-09-09
  • Vite項(xiàng)目搭建與環(huán)境配置的完整版教程

    Vite項(xiàng)目搭建與環(huán)境配置的完整版教程

    Vite?使用?Rollup?作為默認(rèn)的構(gòu)建工具,可以將應(yīng)用程序的源代碼打包成一個(gè)或多個(gè)優(yōu)化的靜態(tài)文件,本文就來為大家介紹一下Vite如何進(jìn)行項(xiàng)目搭建與環(huán)境配置吧
    2023-09-09
  • vue3自定義hooks/可組合函數(shù)方式

    vue3自定義hooks/可組合函數(shù)方式

    這篇文章主要介紹了vue3自定義hooks/可組合函數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • 一文帶你了解Vue3中toRef和toRefs的用法

    一文帶你了解Vue3中toRef和toRefs的用法

    Vue3中toRef、toRefs都是與響應(yīng)式數(shù)據(jù)相關(guān)的,本文主要來給大家講解一下Vue3中的toRef和toRefs的使用,感興趣的朋友跟隨小編一起看看吧
    2023-01-01
  • vue3中的defineExpose使用示例教程

    vue3中的defineExpose使用示例教程

    這篇文章主要介紹了vue3中的defineExpose使用,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-09-09
  • vue3?emits事件使用示例詳解

    vue3?emits事件使用示例詳解

    這篇文章主要為大家介紹了vue3?emits事件使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-07-07
  • vue中for循環(huán)更改數(shù)據(jù)的實(shí)例代碼(數(shù)據(jù)變化但頁(yè)面數(shù)據(jù)未變)

    vue中for循環(huán)更改數(shù)據(jù)的實(shí)例代碼(數(shù)據(jù)變化但頁(yè)面數(shù)據(jù)未變)

    這篇文章主要介紹了vue中for循環(huán)更改數(shù)據(jù)的實(shí)例代碼(數(shù)據(jù)變化但頁(yè)面數(shù)據(jù)未變)的相關(guān)資料,需要的朋友可以參考下
    2017-09-09
  • Vue計(jì)算屬性中reduce方法實(shí)現(xiàn)遍歷方式

    Vue計(jì)算屬性中reduce方法實(shí)現(xiàn)遍歷方式

    這篇文章主要介紹了Vue計(jì)算屬性中reduce方法實(shí)現(xiàn)遍歷方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Vue精美簡(jiǎn)潔登錄頁(yè)完整代碼實(shí)例

    Vue精美簡(jiǎn)潔登錄頁(yè)完整代碼實(shí)例

    這篇文章主要給大家介紹了關(guān)于Vue精美簡(jiǎn)潔登錄頁(yè)完整代碼的相關(guān)資料,通過文中的方法大家可以使用實(shí)現(xiàn)簡(jiǎn)單的用戶登錄界面,下面通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07

最新評(píng)論