vue中img动态绑定src(网络图片https,http)

文章展示了如何在Vue项目中通过在index.html设置referrer策略,然后在组件中使用v-for循环动态绑定img标签的src属性,显示网络图片。图片源来自Gitee,并提供了包含多张图片的数据示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vue访问网络图片

在index.html页面<head>标签中添加

<meta name="referrer" content="no-referrer">

vue中img动态绑定src(网络图片https)

vue绑定img图片资源

<el-row :gutter="20">
  <el-col :span="6"  v-for="item in imgList" :key="item.imgNo">
    <div class="grid-content bg-purple">
      <img :key="item.imgNo" draggable="false" :src="(`${item.src}`)" >
    </div>
  </el-col>
</el-row>

src地址

imgList:[
  {
    imgNo:1,
    src:'https://gitee.com/guo-xiaoya/images/raw/master/img/202304260905239.png',
    width:40,
    height:40
  },
  {
    imgNo:2,
    src:'https://gitee.com/guo-xiaoya/images/raw/master/img/202304260905239.png',
    width:40,
    height:40
  },
  {
    imgNo:3,
    src:'https://gitee.com/guo-xiaoya/images/raw/master/img/202304260905239.png',
    width:40,
    height:40
  },
  {
    imgNo:4,
    src:'https://gitee.com/guo-xiaoya/images/raw/master/img/202304260905239.png',
    width:40,
    height:40
  },
  {
    imgNo:5,
    src:'https://gitee.com/guo-xiaoya/images/raw/master/img/202304260905239.png',
    width:40,
    height:40
  }
],

效果

更多 

Vue中,可以使用v-bind指令或简写的冒号(:)动态绑定img标签src属性根据你提供的代码和需求,请参考以下步骤来实现动态绑定src属性: 1.Vue实例的data属性中定义一个存储图片地址的数组imgList,其中包含多个对象,每个对象代表一张图片,其中包含imgNo、src、width和height属性。 2.Vue模板中,使用v-for指令遍历imgList数组,为每个元素创建一个img标签,并使用:item指令将当前元素绑定到item变量上。 3.img标签中,使用v-bind指令或简写的冒号(:)将item.src绑定src属性上,这样每个img标签src属性都会根据对应的item对象的src属性动态更新。 4. 若要使用网络图片,需要在index.html页面的<head>标签中添加<meta name="referrer" content="no-referrer">,以防止浏览器发送Referer头信息。这样可以绕过一些图片防盗链的限制。 下面是一个示例代码: ```vue <template> <el-row :gutter="20"> <el-col :span="6" v-for="item in imgList" :key="item.imgNo"> <div class="grid-content bg-purple"> <img :key="item.imgNo" draggable="false" :src="item.src"> </div> </el-col> </el-row> </template> <script> export default { data() { return { imgList: [ { imgNo: 1, src: 'https://gitee.com/guo-xiaoya/images/raw/master/img/202304260905239.png', width: 40, height: 40 }, // 其他图片对象 ] }; } }; </script> ``` 通过以上步骤,你可以在Vue中实现动态绑定img标签src属性,以显示不同的图片
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值