国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

Vue瀑布流插件的使用示例

來源:懂視網(wǎng) 責編:小采 時間:2020-11-27 22:07:19
文檔

Vue瀑布流插件的使用示例

Vue瀑布流插件的使用示例:我自己寫的一個的Vue瀑布流插件,列數(shù)自適應(yīng),不用設(shè)置每個卡片的高度。 測試頁面:Page.vue 模板頁面:WaterFollow.vue 和 WFColumn.vue 在Page.vue中,修改itemW的值,設(shè)置每列的最小寬度。例如:itemW=200(意為200px)。list為數(shù)
推薦度:
導讀Vue瀑布流插件的使用示例:我自己寫的一個的Vue瀑布流插件,列數(shù)自適應(yīng),不用設(shè)置每個卡片的高度。 測試頁面:Page.vue 模板頁面:WaterFollow.vue 和 WFColumn.vue 在Page.vue中,修改itemW的值,設(shè)置每列的最小寬度。例如:itemW=200(意為200px)。list為數(shù)

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

測試頁面:Page.vue

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

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

經(jīng)測試,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ò)請求
 // 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>

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

Vue瀑布流插件的使用示例

Vue瀑布流插件的使用示例:我自己寫的一個的Vue瀑布流插件,列數(shù)自適應(yīng),不用設(shè)置每個卡片的高度。 測試頁面:Page.vue 模板頁面:WaterFollow.vue 和 WFColumn.vue 在Page.vue中,修改itemW的值,設(shè)置每列的最小寬度。例如:itemW=200(意為200px)。list為數(shù)
推薦度:
標簽: 使用 VUE 插件
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 久久96国产精品久久久 | 日本乱人伦a综艺网站 | 欧美精品一区二区三区久久 | 欧美国产精品一区二区免费 | 在线国产一区二区 | 九九精品免视看国产成人 | 国产第一夜 | 亚洲欧美日韩电影 | 久久亚洲精品中文字幕60分钟 | 亚洲欧美精品成人久久91 | 亚洲电影中文字幕 | 91视频国产一区 | 黄网站色视频免费观看 | 日韩欧美中字 | 日本a中文字幕 | 国产精品123| 欧美日韩精品一区二区在线播放 | 国产精品自拍一区 | 婷婷在线免费视频 | 欧美午夜视频在线 | 午夜视频在线观看国产 | 国产一区亚洲欧美成人 | 熟年交尾五十路视频在线播放 | 精品综合一区二区三区 | 亚洲激情综合 | 国产69精品久久久久999 | 国产精品三级一区二区 | 国产成人一区二区三区在线播放 | 国产一区二区三区在线视频 | 国产精美视频 | 国产精品国产亚洲精品看不卡 | 国产亚洲午夜精品a一区二区 | 亚洲欧美日韩中文字幕在线 | 欧美另类一区 | 亚洲精品免费视频 | 亚洲国产成人久久综合一 | 亚洲黄色一区二区 | 久久国产一级毛片一区二区 | 青青成人福利国产在线视频 | 99久久国产综合精品成人影院 | 日本美女一区二区 |