image - Img 源将 prop 传递给子组件 Vue Js

标签 image vue.js components react-props

所以,我正在玩 Vue Js,目前在子组件上显示图像时遇到了一些问题,所以,我看起来像这样:

父组件:

<list>
  <post name="post 1" image="somePath"/>
  <post name="post 2" image="somePath"/>
</list>

在我们得到的子组件上

<post>
 <p> {{name}} </p>
 <img src={{somePath}} />
</post>

我用 require 和其他方法尝试了几种方法...... 到目前为止,他们都没有工作...... 有什么建议么? 另外,这是我的 img 路径的样子

"@/assets/web/mock/Phonebeats.png"

最佳答案

只要找到一个方法就可以了! :)

基本上,在初始渲染时,在 vuejs 有机会渲染你的代码之前,浏览器会看到:

<img src="{{ url }}" />

然后浏览器尝试加载 {{ url }} 并失败并显示 404。 您需要使用新的 attr 语法(vue 1.0):

详细

<img v-bind:src="url" />

速记

<img :src="url" />

关于image - Img 源将 prop 传递给子组件 Vue Js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50732500/

相关文章:

javascript - Vue.js - 具有两个行跨度的组件

Textinput 中的 Eclipse RCP 清除按钮

java - "Forwarding"用Java上传图片

java 图像到网格布局

vue.js - vue cli 从浏览器开发控制台检查 css

vue.js - 动态更新值时如何更新vue.js中textarea的高度?

image - 悬停或单击时更改按钮图像

c++ - OpenCV 中的 findContour 可以像 Matlab 中的 bwlabel 一样工作吗?

r - Speedlm更新 "need object with call component"

joomla - 在 joomla 中加载组件 : component, 1 时出错