国产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
主站蜘蛛池模板: 国产成人精视频在线观看免费 | 欧美日韩综合精品一区二区三区 | 在线看国产 | 日韩在线视频一区 | 欧美精品免费在线 | 欧美在线播放视频 | 一级全黄毛片 | 亚洲 另类 在线 欧美 制服 | 中出在线播放 | 成人毛片免费免费 | 国产精品毛片一区二区三区 | 国产全部视频在线播放 | 国产午夜小视频 | 精品国产一区二区三区免费看 | 91一区二区三区 | 免费国产最新进精品视频 | 亚洲最大色网 | 欧美日韩亚洲高清不卡一区二区三区 | 久久精品一区二区国产 | 亚洲视频入口 | 中文国产成人精品久久app | 国产精品高清一区二区三区不卡 | 伊人久久综合成人网小说 | 日韩免费观看 | 欧美精品在线看 | 日韩伦理亚洲欧美在线一区 | 夜夜操夜夜| 欧美日韩亚洲无线码在线观看 | 亚洲视频在线看 | 欧美亚洲一区二区三区在线 | 国产精品免费 | 亚洲第一区在线观看 | 日本美女逼逼 | 国产成人综合久久综合 | 在线播放国产精品 | 精品在线免费播放 | 成人欧美一区二区三区视频不卡 | 久久无码av三级 | 一区二区三区欧美视频 | 在线日韩理论午夜中文电影 | 在线日韩欧美一区二区三区 |