How to implement dynamic :src in Vue.js?
P粉937769356
P粉937769356 2023-09-16 09:38:42
0
1
524

I wish to dynamically render a v-vor image with v-for image src using v-bind:src. Although the images directory seems to be correct (but how do I check that?) and the other array keys are displayed, I don't see the icons in the template.

structure:   src 
                - assets              // 图像内部 
                -components           // 组件内部    
                
<q-card v-for="benefit in benefits" :key="benefit.title">
        <img class="benefits__item-icon" :src="benefit.icon" :alt="benefit.alt">
        <q-card-section >
          <div>{{benefit.content}}</div>
        </q-card-section>
      </q-card>

data() {
      return {
        benefits: [
          {
            icon: '../assets/benefits-icon.svg',  //不显示
            alt: 'benefits',       //正常显示
            title: 'plain text',   //正常显示
            content: 'plain text'   //正常显示
          },
        ]
       }
     }

P粉937769356
P粉937769356

reply all(1)
P粉310754094

Try to change this code

1. <img class="benefits__item-icon" :src="require(benefit.icon)"
    :alt="benefit.alt">
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!