我对Vue比较陌生,我有一个运行中的应用程序,其中包含几个不同的页面。我想要其中一个页面显示在我的主机上找到的所有图片,并在图像更改时自动重新加载它们(另一个应用程序每10秒更新这些图像)。我已经能够显示所有图片(尽管只是通过列出它们),但我似乎无法弄清楚如何让图片自动刷新。以下是代码,请帮忙解决问题。
<template>
<div id="app" class="media-display">
<figure class="media-post" v-for="(image, index) in images" v-bind:key="image.id" >
<img :key="index" :src="getImage(index)" v-bind:alt="image" width="580" height="390" v-bind:key="index" />
</figure>
</div>
</template>
<script>
import moment from 'moment'
export default {
el: '#app',
data(){
return {
images: [
'/charts/chart1.png?rnd='+Math.random(),
'/charts/chart2.png?rnd='+Math.random(),
'/charts/chart3.png?rnd='+Math.random(),
],
id : 1,
}
},
methods: {
getImage(index) {
return this.images[index]
}
}
}
</script>
<style>
.media-post {
display: inline-block;
padding: 1vmin;
//border-radius: 2vmin;
box-shadow: 0 10px 5px rgba(0, 0, 0, 0.2);
margin: 0;
background: #FFF;
position: relative;
cursor: pointer;
}
.media-post img {
//border-radius: 1vmin;
display: block;
max-width: 100%;
height: auto;
}
.media-post figcaption {
color: #FFF;
position: absolute;
top: 0;
left: 0;
font-weight: bold;
padding: 1rem 1.5rem;
z-index: 2;
font-size: 2rem;
text-shadow: 0 1px 2px #000;
}
</style>
Ctrl + Shift + N
)。在data
中的属性在设计上保持不变,除非它们在created
或mounted
钩子期间通过方法更改或分配新值。 - fh0592x