鍍金池/ 問答/HTML/ vue數(shù)據(jù)處理時候?qū)慴acground圖片路徑的格式是怎么樣的

vue數(shù)據(jù)處理時候?qū)慴acground圖片路徑的格式是怎么樣的

<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>

接受數(shù)據(jù)代碼

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: '數(shù)據(jù) error',
      type: 'warning'
    })
  });
  
  **控制臺提示**
  [Vue warn]: Invalid prop: type check failed for prop "index". Expected String, got Undefined.
  
  請問那個background的路徑該用什么格式寫啊
回答
編輯回答
妖妖
<a :style="'background-image: url(' + img.src + ')'"></a>
2018年5月5日 17:54
編輯回答
墻頭草
index:("url(" + require(item.src) + ")"),

改為

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

接口返回的圖片,應(yīng)該不在本地吧,不需要 require

2017年6月10日 08:42