search

Home  >  Q&A  >  body text

javascript - vue-lazyload path problem

Ask a question:

目录
__ src
  |_ assets
     |_imgs
        |_ imgloading.gif
        |_ imgerror.jpg
__ static
  |_ imgloading.gif
  |_ imgerror.jpg
// src/main.js
Vue.use(VueLazyload, {
  error: './assets/imgs/imgerror.jpg',
  loading: './assets/imgs/imgloading.gif',
  preLoad: 1,
  attempt: 1
});

Executionnpm run devReport an error in the browserhttp://localhost:8080/assets/images/.... Cannot find, change the above path to /src/assets/imgs/imgerror.jpgThe same error is reported.
Then I put the image under the static folder at the same level as src, and rewrote the code:

// src/main.js
Vue.use(VueLazyload, {
  error: '../static/imgerror.jpg',
  loading: '../static/imgloading.gif',
  preLoad: 1,
  attempt: 1
});

The picture can be loaded successfully, but I haven’t had a clue for a long time.

欧阳克欧阳克2713 days ago819

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-06-12 09:22:56

    ./assets/imgs/imgerror.jpg It seems that there is no imgs folder in your directory

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-12 09:22:56

    It is said that the path in the template will be parsed by webpack, while the path in js needs to be referenced through import, require or put the image under static for reference

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-12 09:22:56

    require('./assets/imgs/imgerror.jpg')

    reply
    0
  • Cancelreply