vue瀑布流布局

vue版如图:在这里插入图片描述

// 安装组件vue-waterfall2
npn install vue-waterfall2 -S

// main.js 注册使用组件
import waterfall from 'vue-waterfall2'
Vue.use(waterfall)

// list.vue
// 说明下:width/单个列表的宽度,gutterWidth/左列表距右侧的边距(博主这里的动态赋值操作可忽略,因为是为了做示例项目的全端适配)
<template>
	<waterfall 
	:col='2' 
	 :width="(W- ((W<500 && W>=400?400:W>=500?500:W)/375*12)*2-((W<500 && W>=400?400:W>=500?500:W)/375*12))/2" 
	 :gutterWidth="(W<500 && W>=400?400:W>=500?500:W)/375*12"  
	 :data="goods" >
	     <template>
	         <div class="cell-item" v-for="(item,index) in goods" :key="index">
	             <cardList2 class="animated fadeInUp" 
	             :id="'#i'+index" 
	             :goods="item" 
	             @click.native="fndetails(item,index)" 
	             />
	         </div>
	     </template>
	 </waterfall>
 </template>


<script>
import cardList2 from '@/components/cardList2.vue'

let leftHeight=0, rightHeight=0
export default {
	data(){
		return {
			W: document.body.clientWidth || document.documentElement.clientWidth,
			leftList:[],
            rightList:[]
		}
	},

}
</script>


// cardList2.vue
<template>
    <div class="c-box rds _list" :style="{ marginBottom: (W<500 && W>=400?400:W>=500?500:W)/375*12 +'px'}">
        <div class="img-box" :style="{ 'height': clientWidth*(34/75) + 'px' }">
            <img :style="{ 'height': clientWidth*(34/75) + 'px' }" v-lazy="goods.firstPic" :key="goods.firstPic"  alt="">
            <div v-if="state!=4">
                <p class="goodStateTip goodStateTipDJS" v-if="state==4.5">
                        <img class="fs12" style="width:.14rem;height:.14rem;margin-right:.01rem;display:inline-block;" src="../assets/biao.png" alt="">
                        <i class="ing-end-time fs10">{{ time.h }}</i>
                        <b>:</b>
                        <i class="ing-end-time fs10">{{ time.m }}</i>
                        <b>:</b>
                        <i class="ing-end-time fs10">{{ time.s }}</i>
                </p>
                <span class="goodStateTip goodStateTipOther" v-else>{{ nowState }}</span>
            </div>
        </div>
        <div class="text-box">
            <p class="fs14 num2" style="margin-bottom:.1rem;" v-html="goods.title"></p>
            <div class="ai" style="padding:.03rem 0;">
                <ul class="tips clear fs8" style="padding:0;margin-bottom:.05rem;" v-if="goods.originalPrice>0.9 &&goods.rebate && state !=5 && state != 6">
                    <li class="left fan red fs10 hongbao" style="padding:.01rem .05rem;"><i class="fs10"></i><span class="n">{{ goods.rebate }}</span></li>
                </ul>
            </div>

            <div class="ai" style="padding:.03rem 0;">
                <div class="fs11 old-price hui">原价<i class="fs10"></i><span class="n">{{ formatNum(goods.originalPrice || 0) }}</span></div>
            </div>

            <div class="clear price-box ai">
                <span class="left fs12 red now-price"><i class="fs16 bold"><span class="n">{{ formatNum( goods.sellingPrice || 0) }}</span></i></span>
                <span class="right fs12 volume hui">已售<span>{{ goods.salesVolume > 0 ? goods.salesVolume : 0 }}</span></span>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return {
            W: document.body.clientWidth || document.documentElement.clientWidth,
            nowState:'',
            state:'',
            // 倒计时
            time:{
                h: '00',
                m: '00',
                s: '00'
            },
        }
    },
    props:['goods']
 }
 </script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然,我可以为您提供一个使用Vue实现的瀑布流布局案例。 首先,您需要安装Vuevue-masonry-css插件。您可以通过以下命令来安装它们: ``` npm install vue vue-masonry-css``` 接下来,您可以创建一个Vue组件来实现瀑布流布局。下面是一个简单的示例: ```vue<template> <div class="masonry"> <div v-for="(item, index) in items" :key="index" class="item"> <!-- 在这里放置您的内容 --> <img :src="item.imageUrl" alt="Item Image" /> <p>{{ item.title }}</p> </div> </div> </template> <script> import VueMasonryCss from "vue-masonry-css"; export default { name: "MasonryLayout", data() { return { items: [ { imageUrl: "https://example.com/image1.jpg", title: "Item1" }, { imageUrl: "https://example.com/image2.jpg", title: "Item2" }, // 添加更多项目... ] }; }, components: { VueMasonryCss } }; </script> <style scoped> .masonry { display: flex; flex-wrap: wrap; } .item { width:200px; /* 每个项的宽度 */ } </style> ``` 在上述示例中,我们使用了vue-masonry-css插件来实现瀑布流布局。通过在外部容器上添加`.masonry`类,并设置`display: flex; flex-wrap: wrap;`,我们创建了一个弹性布局并使其换行。 每个项使用`.item`类来设置宽度,您可以根据自己的需求进行调整。 在`data`中,我们定义了一个`items`数组来存储每个项目的数据。您可以根据自己的需求修改该数组,并在模板中使用`v-for`指令来循环渲染每个项目。 这只是一个简单的示例,您可以根据自己的需求进行更改和扩展。希望对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值