-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v-binding an image from an object to an img src not working... #42
Comments
Questions should be asked on Stack Overflow or the Vue.js forum. Here is for the issues related to the PWA template. |
I can get it to work outside of the vue-pwa template, tho, so i wondered if it was a template problem. I will ask on the forum as well :-) |
|
ok, I'll close this one and wait for help there then... |
I'm re-opening this because I'm thinking the issue might not be with Vuejs, but with the Webpack configuration in the template, although I don't know for sure... Hi @addyosmani, I'm asking you because I don't know who else put this template together and I don't know if I'm running into a bug or not (it could still easily be me being 'not smart' or something Anyway, do you think anything in the Webpack config could be causing the issue stated above in the first post? The following snippet is from the webpack.base.conf file I've been seeing mentions of this piece in other threads similar to this one, although I don't understand what's going on in the code at all, or how to fix anything. This is the file path... Again, apologies if this is the wrong place for whatever the issue is...I have asked on the Vue JS forum as well, but so far it's been crickets over there... |
I hope it helps you
as you said, it's relevant that how to use webpack and configurations not vue-template. I would give a recommendation you to refer to many of references and guides in the net. templates generated by It looks that url-loader can't fine image resource properly |
Woo Hoo!!! @LinusBorg solved it for me...it was a webpack requirement. Here is his message on the Vuejs Forum: "You have to wrap the path in require('.. /../.....') to let webpack know that it should handle this strong as a dependency. The url-loader that is configured for image file types (is you use our template) will then convert this path that is relative to the component file into a path that is relative to the build files, and it will copy the image to /dist/assets..." Then I wrote back: "Holy Scooby Snacks! It worked, thank you!!! I'm now wondering, however, if there is a better pattern to access images dynamically. Is it possible to not have to specify the backwards travel through the file path... require('../../assets/images/team/richard-nash.jpg') ...and simply ask for the image from the assets folder?... @assets/images/team/richard-nash.jpg' ...so worrying about exact file path position relative to other files and folders is made irrelevant? Is that a thing that is possible, or must we use require and mentally track file paths up and down the apps directory structure? Thank you, again, @LinusBorg ! XD R" Anyway, at the very least the issue is solved for now, and happy to close this one and dive deeper into webpack over the weekend. Thank you for your patience @ragingwind with a newb like myself :-) |
@rchrdnsh thank you for opening and reopening this issue. you just saved my arse (one year later) on a problem I spend 30min figuring out. thanks a lot!!! 👍 |
Hey the require('path') worked for me too. I'm new to Vue and find this one odd, what if the image is messing, this would be a compile error I believe. |
Using: Vue 2.0 + Browserify I had to put the full path to the image and use computed function Path of Images:
Path of Component
Where Shared.websocket.websocket_image_status is one of:
|
Remove relative path and user basUrl
|
I also met the same problem. The solution given by @rchrdnsh solved the problem.
But I also found another solution, to edit the file webpack.config.js, change the chunkhash to hash
|
Hi, json file:
Loop v-for for display
|
Solved.
|
Hi... Can you please explain how you used require??? |
A similar problem has been encountered in a recent project. After reading your article, it has been resolved. Thank you. |
my solution is using export default {
props: {
article: {
type: Object
}
},
computed: {
url: function() {
return `/_nuxt/${this.article.image}`;
}
},
} then use it normally <img v-bind:src="url" alt=""> |
thank you @s4n4s i solved with your solution: but i need add backtick( |
so the solution is Note: Remember to put `` not '' inside require. Because github hides them considering its code. |
Thanks @rchrdnsh. Three years later this "feature" still persists in webpack and Vue.
And it works like a charm. |
Hello @cornesmith! I'll try to use that but an error occurs that says: require is not defined. I'm just a beginner and I'm using vite. And if I'm correct, vite do not use webpack. |
After spending more that four hours looking for the solution it finally worked Using require() in my array |
Yes require also works for me. Thanks |
it also works for me. thx
|
worked for me too, thanks for this! |
Thank you~ This solved it for me. @johnSoneka |
I am facing this issue ./src/components/Home.vue?vue&type=template&id=8dc7cce2 (./node_modules/cache-loader/dist/cjs.js??ref--12-0!./node_modules/babel-loader/lib!./node_modules/vue-loader-v16/dist/templateLoader.js??ref--6!./node_modules/cache-loader/dist/cjs.js??ref--0-0!./node_modules/vue-loader-v16/dist??ref--0-1!./src/components/Home.vue?vue&type=template&id=8dc7cce2) |
Using the require('') helped me solve the problem. |
guys if u are using vite |
Soooo,
...doing this:
...from this:
...and getting this:
The first row in the above pic are from the v-for version and the second row are the static hard coded HTML versions of the same things.
So I dunno why the images are not loading, when all the other data, including the alt stuff is loading...checked the file path of the images, which are fine, so I must be doing something wrong, just don't know what...🤔
Any thoughts are most welcome, thanks! XD
The text was updated successfully, but these errors were encountered: