用vue2在宽400px高600px的div里面用v-for渲染list: [ { name: 'csw1', event: 'hhhhh' }, { name: 'csw2', event: 'hhhhh' }, { name: 'csw3', event: 'hhhhh' }, { name: 'csw4', event: 'hhhhh' }, { name: 'csw5', event: 'hhhhh' }, { name: 'csw6', event: 'hhhhh' }, { name: 'csw7', event: 'hhhhh' }, { name: 'csw8', event: 'hhhhh' }, { name: 'csw9', event: 'hhhhh' }, { name: 'csw10', event: 'hhhhh' },, ],每条数据放在宽400px高200px的盒子里,放的顺序是从上到下,且将溢出的部分隐藏,然后做一个从下往上的轮播,速度是每5秒600px,并且每过60s会通过定时器向list当中添加十条新数据去替换原本的十条数据,轮播无限循环且无缝轮播 
时间: 2023-04-11 07:02:01 浏览: 26
你可以使用以下代码实现:
```html
<template>
<div class="container" style="width: 400px; height: 600px; overflow: hidden;">
<div class="list" style="position: relative; top: 0;">
<div class="item" v-for="(item, index) in list" :key="index" style="width: 400px; height: 200px;">
<p>{{ item.name }}</p>
<p>{{ item.event }}</p>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
list: [
{ name: 'csw1', event: 'hhhhh' },
{ name: 'csw2', event: 'hhhhh' },
{ name: 'csw3', event: 'hhhhh' },
{ name: 'csw4', event: 'hhhhh' },
{ name: 'csw5', event: 'hhhhh' },
{ name: 'csw6', event: 'hhhhh' },
{ name: 'csw7', event: 'hhhhh' },
{ name: 'csw8', event: 'hhhhh' },
{ name: 'csw9', event: 'hhhhh' },
{ name: 'csw10', event: 'hhhhh' },
],
currentIndex: 0,
};
},
mounted() {
setInterval(() => {
this.currentIndex++;
if (this.currentIndex >= this.list.length) {
this.currentIndex = 0;
}
this.scrollList();
}, 5000);
setInterval(() => {
const newList = [];
for (let i = 0; i < 10; i++) {
newList.push({ name: `new${i}`, event: 'new event' });
}
this.list.splice(this.currentIndex, 10, ...newList);
}, 60000);
},
methods: {
scrollList() {
const list = this.$el.querySelector('.list');
const itemHeight = 200;
const top = -this.currentIndex * itemHeight;
list.style.top = `${top}px`;
},
},
};
</script>
```
在这个代码中,我们使用了一个容器 `container` 来限制显示区域的大小,并将溢出的部分隐藏。我们使用了一个列表 `list` 来存储数据,并使用 `v-for` 指令将数据渲染到页面上。每个数据都被放在一个宽400px高200px的盒子里。我们使用了一个定时器来实现从下往上的轮播,每5秒滚动600px,并且每过60秒会添加十条新数据。我们使用了一个 `currentIndex` 变量来记录当前显示的数据的索引,以便在定时器中更新显示的数据。我们使用了一个 `scrollList` 方法来更新列表的位置。
相关推荐
