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

Vue瀑布流插件的使用示例

 更新時(shí)間:2018年09月19日 10:20:16   作者:歡舞的螢火蟲  
這篇文章主要介紹了Vue瀑布流插件的使用示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

我自己寫的一個(gè)的Vue瀑布流插件,列數(shù)自適應(yīng),不用設(shè)置每個(gè)卡片的高度。

測(cè)試頁面:Page.vue

模板頁面:WaterFollow.vue 和 WFColumn.vue

在Page.vue中,修改itemW的值,設(shè)置每列的最小寬度。例如:itemW="200"(意為200px)。list為數(shù)組。高度不用設(shè)置,:style="{height:item+'px'}"是我為了創(chuàng)造卡片高度加上去的,不加就顯示卡片的原來大小。

經(jīng)測(cè)試,created加載數(shù)據(jù)正常,mounted加載、更新數(shù)據(jù)正常。

Page.vue

<template>
 <div class="container">
  <w-f-column itemW="200">
   <template slot-scope="{columnNum,columnIndex}">
    <water-follow :list="list" :columnNum="columnNum" :columnIndex="columnIndex">
     <template slot-scope="{item,index}">
      <div class="my-box" :style="{height:item+'px'}">{{item}}-{{index}}</div>
     </template>
    </water-follow>
   </template>
  </w-f-column>
 </div>
</template>

<script>
import WFColumn from '../waterFollow/WFColumn'
import WaterFollow from '../waterFollow/WaterFollow'
export default {
 name: 'page',
 components: {WaterFollow, WFColumn},
 data () {
  return {
   list: []
  }
 },
 created () {
  // 有初始數(shù)據(jù)
  for (let i = 0; i < 50; i++) {
   this.list.push(Math.floor(Math.random() * 301 + 200))
  }
 },
 mounted () {
  // 模擬網(wǎng)絡(luò)請(qǐng)求
  // window.setTimeout(() => {
  //  this.list = []
  //  for (let i = 0; i < 50; i++) {
  //   this.list.push(Math.floor(Math.random() * 301 + 200))
  //  }
  // }, 1000)
  // -- 分割 --
  // 模擬數(shù)據(jù)不斷變化
  // window.setInterval(() => {
  //  this.list = []
  //  for (let i = 0; i < 50; i++) {
  //   this.list.push(Math.floor(Math.random() * 301 + 200))
  //  }
  // }, 1000)
 }
}
</script>

<style scoped lang="scss">
 .container{
  width: 100%;
  background: gray;
  .my-box{
   width: 200px;
   background: #000;
   margin-bottom: 20px;
   color: #fff;
  }
 }
</style>

WFColumn.vue

<template>
 <div class="wf-container">
  <div class="wf-column" v-for="(item,index) in columnNum" :key="'column-'+index" :name="index">
   <slot :columnNum="columnNum" :columnIndex="index"></slot>
  </div>
 </div>
</template>

<script>
export default {
 name: 'WFColumn',
 props: ['itemW'],
 data () {
  return {
   columnNum: 0
  }
 },
 created () {
  this.columnNum = Math.floor(document.body.clientWidth / this.itemW)
  window.onresize = () => {
   this.columnNum = Math.floor(document.body.clientWidth / this.itemW)
  }
 }
}
</script>

<style scoped lang="scss">
.wf-container{
 width: 100%;
 display: flex;
 .wf-column{
  flex: 1;
 }
}
</style>

WaterFollow.vue

<template>
 <div>
  <div v-for="(item,index) in list" :key="'item-'+index" class="item" :id="'card-'+columnIndex+'-'+index" v-if="load?(record[index].index===columnIndex):true">
   <slot :item="item" :index="index"></slot>
  </div>
 </div>
</template>

<script>
export default {
 name: 'WaterFollow',
 props: ['list', 'columnNum', 'columnIndex'],
 data () {
  return {
   column: 0,
   record: [],
   load: false,
   update: false
  }
 },
 methods: {
  calculateColumn () {
   let cList = []
   for (let i = 0; i < this.columnNum; i++) {
    cList.push(0)
   }
   for (let i = 0; i < this.record.length; i++) {
    let index = 0
    for (let j = 0; j < cList.length; j++) {
     if (cList[index] > cList[j]) {
      index = j
     }
    }
    cList[index] += this.record[i].height
    this.record[i].index = index
   }
  },
  recordInit () {
   for (let i = 0; i < this.list.length; i++) {
    this.record.push({index: -1, height: -1})
   }
  },
  initHeightData () {
   for (let i = 0; i < this.list.length; i++) {
    if (document.getElementById('card-' + this.columnIndex + '-' + i)) {
     let h = document.getElementById('card-' + this.columnIndex + '-' + i).offsetHeight
     this.record[i].height = h
    }
   }
  }
 },
 beforeCreate () {},
 created () {
  this.load = false
  this.recordInit()
 },
 beforeMount () {},
 mounted () {
  this.initHeightData()
  this.calculateColumn()
  this.load = true
 },
 beforeUpdate () {},
 updated () {
  if (this.update) {
   this.initHeightData()
   this.calculateColumn()
   this.update = false
   this.load = true
  }
 },
 beforeDestroy () {},
 destroyed () {},
 watch: {
  columnNum (curr, old) {
   this.calculateColumn()
  },
  list (curr, old) {
   console.log('list change')
   this.recordInit()
   this.load = false
   this.update = true
  }
 }
}
</script>

<style scoped>
</style>

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

相關(guān)文章

  • vue實(shí)現(xiàn)導(dǎo)航欄下拉菜單

    vue實(shí)現(xiàn)導(dǎo)航欄下拉菜單

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)導(dǎo)航欄下拉菜單,帶展開收縮動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-09-09
  • vue自定義指令之面板拖拽的實(shí)現(xiàn)

    vue自定義指令之面板拖拽的實(shí)現(xiàn)

    這篇文章主要介紹了vue自定義指令之面板拖拽的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • VSCode使用之Vue工程配置eslint

    VSCode使用之Vue工程配置eslint

    這篇文章主要介紹了VSCode使用之Vue工程配置eslint,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-04-04
  • 詳解vue-template-admin三級(jí)路由無法緩存的解決方案

    詳解vue-template-admin三級(jí)路由無法緩存的解決方案

    這篇文章主要介紹了vue-template-admin三級(jí)路由無法緩存的解決方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • 一文掌握在Vue3中書寫TSX的使用方法

    一文掌握在Vue3中書寫TSX的使用方法

    但隨著vue3版本的到來,對(duì)typescript的支持度越來越高,tsx語法也被大部分人越來越接收,所以很多項(xiàng)目都是搭配 Vue3 + TS 進(jìn)行的,這篇文章主要介紹了一文掌握在Vue3中書寫TSX的方法,需要的朋友可以參考下
    2023-05-05
  • vue實(shí)現(xiàn)鼠標(biāo)滑動(dòng)展示tab欄切換

    vue實(shí)現(xiàn)鼠標(biāo)滑動(dòng)展示tab欄切換

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)鼠標(biāo)滑動(dòng)展示tab欄切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • vue 中 get / delete 傳遞數(shù)組參數(shù)方法

    vue 中 get / delete 傳遞數(shù)組參數(shù)方法

    這篇文章主要介紹了vue 中 get / delete 傳遞數(shù)組參數(shù)方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-03-03
  • Vue3組件異步更新和nextTick運(yùn)行機(jī)制源碼解讀

    Vue3組件異步更新和nextTick運(yùn)行機(jī)制源碼解讀

    這篇文章主要為大家介紹了Vue3組件異步更新和nextTick運(yùn)行機(jī)制源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • vue+Ant?Design進(jìn)度條滑塊與input聯(lián)動(dòng)效果實(shí)現(xiàn)

    vue+Ant?Design進(jìn)度條滑塊與input聯(lián)動(dòng)效果實(shí)現(xiàn)

    最近接到這樣一個(gè)需求滑塊進(jìn)度與輸入框?yàn)橐恢?默認(rèn)值為80,最小不能小于30,最大為100,怎么實(shí)現(xiàn)這個(gè)聯(lián)動(dòng)效果呢,下面小編給大家分享下基于vue+Ant?Design進(jìn)度條滑塊與input聯(lián)動(dòng)效果的實(shí)現(xiàn),感興趣的朋友跟隨小編一起看看吧
    2022-12-12
  • Vue使用provide各種傳值后inject獲取undefined的問題及解決

    Vue使用provide各種傳值后inject獲取undefined的問題及解決

    這篇文章主要介紹了Vue使用provide各種傳值后inject獲取undefined的問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08

最新評(píng)論

富顺县| 民丰县| 淅川县| 温州市| 左云县| 溆浦县| 仪征市| 吉木萨尔县| 河津市| 达孜县| 麦盖提县| 平湖市| 玉屏| 柞水县| 龙川县| 朝阳市| 金昌市| 湖南省| 辽源市| 那曲县| 四会市| 都昌县| 大厂| 广饶县| 尚志市| 雷山县| 郎溪县| 赤峰市| 普安县| 福州市| 尼木县| 沁阳市| 克山县| 文水县| 龙南县| 彭水| 河池市| 西华县| 红桥区| 仙桃市| 尖扎县|