为了账号安全,请及时绑定邮箱和手机立即绑定

vue数据处理时候写bacground图片路径的格式是怎么样的

vue数据处理时候写bacground图片路径的格式是怎么样的

大话西游666 2019-03-22 15:19:18
<el-carousel :interval="3500" arrow="always" >  <el-carousel-item  v-for="img in carouselFigures" :key="img.id">    <a  :style="{background: img.index}" target="_blank" class="aaa">    </a>  </el-carousel-item></el-carousel>接受数据代码const that = this;console.log(that);//轮播图this.$http.get(  that.$interface_+'getRecentImgs')  .then(function (response) {    if(response.data.status === 1){      response.data.data.forEach(function(item){        that.carouselFigures.push({          src:item.location,          index:("url(" + require(item.src) + ")"),          description:item.description        });      });    }else{      that.$message({        message: response.data.msg,        type: 'warning'      });    }  })  .catch(function (err) {    console.log(err);    that.$message({      message: '数据 error',      type: 'warning'    })  });    **控制台提示**  [Vue warn]: Invalid prop: type check failed for prop "index". Expected String, got Undefined.    请问那个background的路径该用什么格式写啊
查看完整描述

2 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

<a :style="'background-image: url(' + img.src + ')'"></a>


查看完整回答
反对 回复 2019-04-09
?
侃侃尔雅

TA贡献1801条经验 获得超16个赞

index:("url(" + require(item.src) + ")"),

改为

index:("url(" item.src + ")"),

接口返回的图片,应该不在本地吧,不需要 require


查看完整回答
反对 回复 2019-04-09
  • 2 回答
  • 0 关注
  • 606 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号