微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用动态图片 src 作为 prop Vue

如何解决使用动态图片 src 作为 prop Vue

我正在尝试将动态 src 作为 prop 发送到 imageComponent,但我做错了。 fileName = about.gsx$imagesrc.$t 不起作用。图像存储在资产/图片中,about.gsx$imagesrc.$t 与图像名称的值相同。

<template>
  <div class="timeline">
    <div class="timeline-content" v-for="about in state.aboutData" :key="about.index">
      
        <div class="fill-circle">
          <h2 class="timeline-year" > {{about.gsx$year.$t}}</h2>
        </div>
      <p class="timeline-text" > {{about.gsx$happening.$t}} </p>

        <ImageComponent
          //Filename is the problem
          fileName= about.gsx$imagesrc.$t
          leftPosition="200px"
          activeColor="#132766"
        />
     
    </div>
  </div>
</template>

<script>
import { state } from '@/store/index.js'
import ImageComponent from "@/components/UI-kit/PictureModules/Sko.vue"

export default {
  name:"Timeline",components: {ImageComponent},}

图像组件

<template>
    <div class="ImageComponent" v-bind:style="{ left: leftPosition}">
        <img class="image" :src="require(`@/assets/Pictures/${fileName}`)">
        <div class="shadow" v-bind:style="{ backgroundColor: activeColor}"></div>
    </div>
</template>

<script>
export default {
    name:"ImageComponent",props: {
        activeColor: [String],leftPosition: [String],fileName: [String],}
}
</script>

这是我得到的错误

渲染错误:“错误:找不到模块'./about.gsx$imagesrc.$t'”

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。