Webpack: v-bind:src=" ....imgurl..." not added to static/img?

Created on 18 Sep 2016  路  2Comments  路  Source: vuejs-templates/webpack

Hi,

When I'm using v-bind:src for images they show up as broken because they are not put in the build folder in /static/img/, as opposed to regular src="". Why is this and how do I fix it? I can't manually add stuff to the build folder because they are overwritten on build.

So to make it clear:
this works:
<img src="pathtoimg/img.jpg">

But this do not:
<img v-for="image in images" v-bind:src="image.url">

I have the same issue trying to access data from json files, I cant put them anywhere and access the data it seems? Because it's not in the build?

Most helpful comment

where do you keep those images before build?

The problem likely is: this

  • For non-bound src attributes Webpack (or more specifically: html-loader) can read those src paths and copies the files from the specified path to the assets directory in the build folder.
  • For dynamic, bound paths, webpack can't do that, of course.

So you will have to put those images into /<your project root folder>/static/ instead of placing them somewhere in /src/assets., because /static will be copied into /dist/ as-is.

All 2 comments

where do you keep those images before build?

The problem likely is: this

  • For non-bound src attributes Webpack (or more specifically: html-loader) can read those src paths and copies the files from the specified path to the assets directory in the build folder.
  • For dynamic, bound paths, webpack can't do that, of course.

So you will have to put those images into /<your project root folder>/static/ instead of placing them somewhere in /src/assets., because /static will be copied into /dist/ as-is.

@LinusBorg I see, thanks for clearing that up for me=)

Was this page helpful?
0 / 5 - 0 ratings