【问题标题】:Vue.js image v-for bindVue.js 图像 v-for 绑定
【发布时间】:2017-12-10 11:04:39
【问题描述】:

有什么方法可以使用 v-for 来加载图像数组?

已尝试使用以下代码:

我对 Vue 还很陌生,我还有很多东西要学。因此,任何帮助将不胜感激。谢谢

<template>
      <section class="hero_home">
         <app-header></app-header>
          <article>
            <h1>About</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est, aperiam doloremque possimus nemo incidunt, consequatur quidem facere in ipsam ratione quod? Provident laborum magnam accusantium sequi optio error sunt, sit.</p>
        </article>

            <img v-for="image in images" :src="images.url" :alt="images.alt" />
        
        <app-footer></app-footer>
      </section>
</template>


<script>
    import Header from './header.vue'
    import Footer from './footer.vue'
    
    export default {
        components: {
            'app-header': Header,
            'app-footer': Footer
        },
      data () {
        return {
            images: [
                { url: '../static/1.jpg', alt: 'I love you nature' },
                { url: '../static/2.jpg', alt: 'Now with dog - Rosé' },
                { url: '../static/3.jpg', alt: 'Jeg er i Danmark' },
                { url: '../static/4.jpg', alt: 'Badabimbadabum' },
                { url: '../static/5.jpg', alt: 'Goodmorning el mundo' },
                { url: '../static/6.jpg', alt: 'My white and rosé with paella' },
                { url: '../static/7.jpg', alt: 'Hopla' },
                { url: '../static/8.jpg', alt: 'Watering by night' },
                { url: '../static/9.jpg', alt: 'Life aint so bad at all...' },
                { url: '../static/10.jpg', alt: 'My whitewine' },
                { url: '../static/11jpg', alt: 'First time for everything...winefair!' },
                { url: '../static/12.jpg', alt: 'Lost around 20% of this years yield!' }
            ]
        }
      }
    }
</script>

【问题讨论】:

    标签: javascript vue.js


    【解决方案1】:

    srcalt 中使用image 对象元素,而不是images 对象数组。

    <img v-for="image in images" :src="image.url" :alt="image.alt" />
    

    【讨论】:

    • 非常感谢 Rishi!
    猜你喜欢
    • 1970-01-01
    • 2021-07-19
    • 2021-02-20
    • 2020-07-18
    • 1970-01-01
    • 2019-12-09
    • 2019-03-27
    • 2021-02-08
    • 2023-04-08
    相关资源
    最近更新 更多