vue實(shí)現(xiàn)簡(jiǎn)單瀑布流布局
vue簡(jiǎn)單實(shí)現(xiàn)瀑布流布局的一種方式(vue瀑布流組件),供大家參考,具體內(nèi)容如下
vue中的瀑布流布局組件
需求:圖片容器寬度固定,高度根據(jù)圖片自適應(yīng),圖片一行不能排列時(shí)候,換行依次從左往右排列。(瀑布流概念)
另外結(jié)合vue-lazy實(shí)現(xiàn)懶加載 ( npm i vue-lazyload --save-dev)使用也很簡(jiǎn)單,在需要懶加載的img標(biāo)簽上將:src換成v-lazy
父組件傳遞數(shù)據(jù):
waterfallData:[ { e_img: 'test.jpg', // 圖片 e_intro: '描述信息', u_img: 'test.jpeg', // 標(biāo)記圖 u_name: '開(kāi)發(fā)者'}, { e_img: 'test.jpg', e_intro: '描述信息', u_img: 'test.jpeg', u_name: '開(kāi)發(fā)者'} ]
定寬不定高瀑布流布局子組件
<template><div> <div v-cloak> <ul v-for='(el,i) in newWaterfallData' :key='i'> <li v-for='(item,index) in el' :key='index'> <div > <router-link to='/goodsdetail/1'> <img v-lazy='item.e_img' alt='' v-loading='true'> </router-link> <div v-if='item.u_img'> <img :src='http://www.aoyou183.cn/bcjs/item.u_img' alt='' > </div> <h3 v-if='item.e_intro'> {{item.e_intro}}</h3> </div> </li> </ul> </div></div></template><script>export default { data() { return { newWaterfallData: ’’, waterfallDataNumber:’’ } }, created() { let [ ...waterfallData ] = this.waterfallData let [ ...newWaterfallData ]= [[],[],[]] waterfallData.forEach((el,i) => { switch( i%3 ) { case 0 : newWaterfallData[0].push(el) break case 1: newWaterfallData[1].push(el) break case 2: newWaterfallData[2].push(el) break } }); this.newWaterfallData = newWaterfallData }, props: [ ’waterfallData’ ]}</script><style lang='scss'> .px-container { width: 100%; max-width: 1200px; margin: 0 auto; } .clearfix:before, .clearfix:after { content: ''; display: block; clear: both; } .clearfix { zoom: 1; } .left { float: left; } . font22{ font-size:22px; } .color-fff { color:#fff; } .fh { overflow:hidden; } [v-cloak]{ display: none!important; } .waterfall { margin-top: 20px; } .px-waterfall { width: calc(380px); &:nth-child(3n+2) { margin: 0 30px; } img.bg-img { border-radius: 8px; } h3 { text-overflow:ellipsis; white-space: nowrap; text-overflow: ellipsis; height:30px; font-family:PingFangSC-Semibold; font-weight:600; line-height:30px; letter-spacing:6px; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 999; } li{ background: #fff; border-radius: 8px; margin-bottom: 20px; } } .px-hot-tag { position: absolute; top: 0; border-radius: 8px; width: 71px; height: 30px; img { border-radius: 8px 0 8px 0; } } .photo{ position: relative; height: 25px; .keywordbox { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); height: 25px; } } .keyword { height: 25px; line-height: 25px; padding: 0 22px; text-align: center; .color-666-line { border-bottom:2px solid #666666; } .red-line { border-bottom:2px solid #F65050; } }</style>
如有問(wèn)題,歡迎指正,如您有好的方案,敬請(qǐng)與我分享!
更多文章可以點(diǎn)擊《Vue.js前端組件學(xué)習(xí)教程》學(xué)習(xí)閱讀。
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專(zhuān)題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專(zhuān)題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案2. ASP.NET泛型三之使用協(xié)變和逆變實(shí)現(xiàn)類(lèi)型轉(zhuǎn)換3. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))4. 如何在jsp界面中插入圖片5. XML基本概念XPath、XSLT與XQuery函數(shù)介紹6. JS中map和parseInt的用法詳解7. PHP循環(huán)與分支知識(shí)點(diǎn)梳理8. jsp實(shí)現(xiàn)登錄界面9. AspNetCore&MassTransit Courier實(shí)現(xiàn)分布式事務(wù)的詳細(xì)過(guò)程10. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析
