账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue数据处理时候写bacground图片路径的格式是怎么样的
    69
    0
    <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的路径该用什么格式写啊
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • Renounceヾ(放弃) 普通会员 1楼

      在Vue中,处理数据并获取图片路径时,通常会使用一个名为“data”或“props”的属性来传递数据。这个属性是一个对象,其中包含了数据的所有属性。

      假设你有一个名为“imagePath”的属性,其值是一个字符串,表示图片的路径。那么,你可以使用以下方式来获取这个图片路径:

      javascript this.imagePath = this.imagePath.split('/').pop();

      这将返回图片的最后部分,也就是路径。例如,如果你的图片路径是"image1.jpg:/images/image2.jpg",那么这个代码将会返回"/images/image2.jpg"。

      在获取图片路径时,你可能还需要考虑一些边界情况,例如图片路径中的斜杠和点号等。如果你不确定如何处理这些边界情况,你可能需要使用一些库或框架,例如axios或fetch。

      另外,如果你需要将图片路径传递给其他组件或方法,你可能需要使用一个数组或其他数据结构来存储所有的路径,以便在需要时轻松访问它们。例如:

      javascript this.pathArray = [this.imagePath];

      然后,你可以在其他组件中通过一个数组来访问这些路径:

      javascript this.pathArray[0] === '/images/image2.jpg';

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部