Nuxt picture problem

use: src= "item.url"
Why can"t you bind a picture in this way? it can only be written as static

.

or write

in data

data () {

return {
    item: {
        url: require("~/assets/img/home.png")
    }
}

}

Why would it not work to use direct: src= "item.url"?

Apr.11,2021

because you write it statically, it will be compiled by webpack to get the correct real path of the packaged image.
if you write dynamic, webpack will not compile, and put '~ / assets/img/home.png' in the src of your picture intact. Do you have this picture in https://img.codeshelper.com/upload/img/2021/04/11/gveaturhrqb16048.png?


put the picture in the static directory and change it to this

require('static/img/home.png')

the path where your url is'~ / assets/img/home.png', is not accessible under your server.

you can put this picture on cdn, or under a path that your server can access directly.


Hello. Did you ask this question?

Menu