vue: Image src attribute causes a 404 before the compilation
Hello,
with a template like this:
<img src="{{image}} />
and javascript:
var vue = new Vue({
el: '#view',
data: {
image: 'http://somehost.com/image.jpg'
}
});
gives the error:
GET http://myhost.com/%7B%7Bthumb%7D%7D 404 (Not Found)
The Angular team had some issue with it, which resulted in the ngSrc directive.
NB: The same problem might happen with the href attribute, see ngHref as well.
Edit: Here comes the JSFiddle.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 1
- Comments: 18 (2 by maintainers)
You can use
v-attr="src: image"in this situation@dickyeka the v-bind:src (or :src) evaluates an expression, you would need the following:
<img :src="'img/category/'+c.image" />can anyone explain that if only one loop used, we can use src=‘xxxx’ without getting 404 error? in my case, error only occur in nested loops
data used:
@raywill As explained above use
<img v-bind:src="p.url">or<img :src="p.url">template syntax error - invalid expression: v-attr=“src: image”
@aztack the recommended way is to use
v-bind:src="item.src"or the shortcut:src="item.src".v-bind="..."is there for cases when you want to construct the list of attributes programmatically.@surgiie is there your images content a white space at the first character?
%07at url encode mean white space. if its true, so try totrim()your images before its load. so your code looks like bellow :