图片路径问题(静态、动态)

(1)<img src="../assets/img/favicon.ico">
(2)
v-for="u in list"
<img class="pic" :src="require('../assets/'+u.avatar)">

(3)示例1:(图片排列比较整齐时)

this.$http.get("http://localhost/wyyx/indexProList.php",{emulateJSON:true,withCredential:true}).then((response)=>{
        this.pList1=response.body;
      })
<div>
            <img v-for="p in pList1" :src="require('../assets/'+p.img_path)">
          </div>

(4)示例2:(图片排列不整齐且图片比较时)

this.$http.get("http://localhost/wyyx/indexProduct.php",{emulateJSON:true,withCredentials:true}).then((response)=>{
        this.path1=require('../assets/'+response.body[0][1]);
        this.path2=require('../assets/'+response.body[1][1]);
        this.path3=require('../assets/'+response.body[2][1]);
        this.path4=require('../assets/'+response.body[3][1]);
      })
<div>
            <img :src="path1" alt="">
          </div>
          <div>
            <img :src="path2" alt="">
          </div>
          <div>
            <img :src="path3" alt="">
            <img :src="path4" alt="">
          </div>

这里我本来是用pList[0]、pList[1]....,结果发现vue不认账呀,所以就使用了四个变量

还有,最最重要的一点是,当非常肯定自己的代码正确却发现效果不对时,请重启服务器,vue服务器有时不稳定哦!!!!!

补:

发现有时在html上加require会报错,当报错时可以在js中先require后再放入html中





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值