小编Soo*_*hae的帖子

如何在nuxt项目中传递动态图片url

我想将图像 url 传递给子组件,但图像未显示。

我试过v-attr, :attr,:src属性。

页面/index.vue

<ThumbNail img-url="assets/img/igsim_intro.png"/>
Run Code Online (Sandbox Code Playgroud)

组件/缩略图.vue

<!-- Failed to resolve directive: attr -->
<img v-attr="imgUrl" /> 

<!-- 404 Not found: http://localhost:3000/assets/img/pds_main.png -->
<img :src="imgUrl" />

<img :attr="{src: imgUrl}" /> 
Run Code Online (Sandbox Code Playgroud)
<script>
export default {
  name: "ThumbNail",
  props: {
    imgUrl: {
      type: String,
      default: ''
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

我希望Thumbnail.vue将图像显示为传递的 url。

config vue.js nuxt.js

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

config ×1

nuxt.js ×1

vue.js ×1