vue 打包之后拿不到 原先 static 文件里的 图片

vue 打包之后拿不到 原先 static 文件里的 图片

关于vue 打包是一个 困扰了很多初学者的问题,当然包括我。不过vue-cli 已经优化的很好

关于路径问题,百度上有很多,就是在

修改:
这个文件下的
  build :   {
     // Template for index.html
    index :   path . resolve ( __dirname ,   ' ../dist/index.html ' ) ,

     // Paths
    assetsRoot :   path . resolve ( __dirname ,   ' ../dist ' ) ,
    assetsSubDirectory :   ' static ',
    assetsPublicPath :   ' / ',   //   ==>  './'

确实能将打包以后的资源路径指向打包以后的文件夹。但是我使用 静态文件路径的 却拿不到

imgSrc : [
' /static/img/footer/tab11.png ' ,
' /static/img/footer/tab21.png ' ,
' /static/img/footer/tab31.png '
]

这种路径的一个算一个,都拿不到。

然后看打包以后的文件结构,发现只需要在路径变成相对路径

imgSrc : [
' . /static/img/footer/tab11.png ' ,
' ./static/img/footer/tab21.png ' ,
' ./static/img/footer/tab31.png '
]

就能拿到。

但是当我修改标签上的 static(不要问我为什么要在标签上使用 static 文件里的东西,当时脑抽)

< img slot = " icon " src = " ./static/img/footer/tab4.png " >

结果报错了。。。打包也会报一堆错

然后想着既然这样,索性破罐子破摔,把这个改成 绑定的属性

< img slot = " icon " : src = " '. /static/img/footer/tab4.png ' " >
就能拿到了。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值