-
Notifications
You must be signed in to change notification settings - Fork 17
img src data binding? #202
Comments
You should use |
@azamat-sharapov ah i see, missed that, thanks for the pointers. |
Thanks! |
I also have the same problem. In NewsCard.vue:
In HomePage.vue:
I always get 404 for the image. But if i put directly the image url in the NewsCard.vue everything works fine. The app structure: src Vuejs: 1.0.17 |
On initial rendering, before vuejs got a chance to even render your code, the browser sees this: <img src="{{ url }}" /> The browser then tries to load <!-- verbose -->
<img v-bind:src="url" />
<!-- shorthand -->
<img :src="url" /> Please see the documentation for details. |
@nirazul Thank for replying I tried but i did not work out. Here is the sample test I made: |
could you translate this in a codepen? |
The problem is with the local images not the online ones. I tried to use online image with my example. Everything is fine! I cannot load local images. So i cannot do it in online editor! |
@nirazul, Thanks a lot!! |
Is there a way to solve this local image issue yet? I am also experiencing the same problem as @vinhtq |
+1 Same issue. Local images in /assets/ directory aren't loading. Using the webpack template from vue-cli. Using v-bind:src with the img tag. I ended up solving this by putting the images in the /static/ directory. Worked fine. But I'm curious why the assets path (./assets/img/ ...) won't display the image. Is it because I'm using an /img/ subdirectory in assets? EDIT: the Vue 'V' loads fine from /assets/ with a non-dynamic path (./assets/logo.png). |
@cschweda, Thanks a lot! |
I am having the same issue as @cschweda the images inside /assets/images/ aren't loading for me. Did anyone figure out why? |
When you have rooted path (staring with /), are you expecting the assets folder to be present under your dist folder? I think the behavior you are noticing is because assets folder is relative to src folder and vue-loader copies the images under assets to dist folder applying webpack config rules. |
So you're saying, it'll copy logo.png because it's in /assets/ -- but if I Should I explicitly tell Webpack to copy any subfolder under assets?
(Not sure if that's the right syntax) |
In the webpack rules for file-loader module
And in your .vue file
|
Awesome. Thank you! On Mon, Nov 14, 2016 at 5:02 PM, chandmk notifications@github.com wrote:
|
this does not work. I still get a 404:
Had to move to |
for anyone still encountered dynamic loading issue with webpack, could be helpful to take a look at following links:
|
Any nice workarounds for this?? I don't want to mess with |
Thanks @nirazul - works fine for me |
Thanks @chovy ! |
Sorry for reArchive this, but this stack is helping a lot with one function, and nothing with vue config change: http://stackoverflow.com/questions/40491506/vue-js-dynamic-images-not-working |
Thank you, after days of searching I came across your post. This solution worked for me, I am also referencing this discussion and your link in an issue I filed : vuejs/vue-loader#814 |
Writing a method doesn't work for me. Instead, try importing img in JS, this works for me. See this issue |
this is way too complicated for nothing wow. |
|
@latovicalmin Using require in data gives a |
This worked for me - While giving the path in your data, give the full path from your project root folder -
|
Importing the image works like a charm.
and then in your HTML:
|
This should work for you guys ES2015 Style:
Or without ES2015:
|
@stablestorage the image path in your first example needs to be wrapped in backticks to interpolate with the
|
@latovicalmin it works for me |
I've had success with @latovicalmin 's solution.
url () {
const url = require(`@/assets/${this.article.code}.jpg`)
return url
} While this worked in development, in production all my links were broken. It tried to fetch To fix this issue, I had to drop a script tag in my html page (served by IIS), to include the actual website root, like this (in cshtml) : <script>
var ROOT = '@Url.Content("~/")';
</script> and then fix my url resolving method like this : url () {
const url = require(`@/assets/${this.article.code}.jpg`)
return ROOT + url.substr(1)
} Maybe it would be nice to use the actual application's root instead of |
Worked with me
|
Thanks Nirazul, it works just fine. |
|
This is way for me, its working fine for me.. <div class="page" v-for="pic in pics">
<img class="landscape" :src="`/static/img/${pic}`">
</div> |
Hi,
I have a html tag
As you can see i am biding data imageLink to the html image src tag, it works, image is displayed as normal, but Chrome shows a 404 not found on the image link since its checking on the html img src syntax.
Is the way i'm doing correct or there is a better way?
The text was updated successfully, but these errors were encountered: