vue中require动态加载图片

<template>
  <img src="D:/images/01.png" alt="静态加载">

  <img :src="require('D:/images/01.png')" alt="动态加载1">

</template>

如果需要加载图片列表路径list = [imgpath,imgpath1,imgpath2, ...]时,使用require(imgpath)加载可能加载不出甚至报错,这是因为require动态加载解析图片路径没有静态地址,imgpath = 静态地址+图片地址,如

<template>
  <img src="D:/images/01.png" alt="静态加载">
  <img :src="require('D:/images/'+'01.png')" alt="动态加载2">
</template>

  加上静态地址后就可以了

posted @ 2023-03-03 15:51  sycl  阅读(114)  评论(0编辑  收藏  举报