Vue组件图片加载注意事项!!!

!!!很重要

vue组件加载图片

<template>
  <ul class="btmNav">
    <li>
      <a href="javascript:;" @click="change('/home')">
        <img
          :src="
            '/home' === this.$route.path
              ? iconArr[0].selecetd
              : iconArr[0].normal
          "
          alt=""
        />
        <p :class="['name', '/home' === this.$route.path ? 'checked' : '']">
          首页
        </p>
      </a>
    </li>
    <li>
      <a href="javascript:;" @click="change('/category')">
        <img
          :src="
            '/category' === this.$route.path
              ? iconArr[1].selecetd
              : iconArr[1].normal
          "
          alt=""
        />
        <p :class="['name', '/category' === this.$route.path ? 'checked' : '']">
          分类
        </p>
      </a>
    </li>
    <li>
      <a href="javascript:;" @click="change('/special')">
        <img
          :src="
            '/special' === this.$route.path
              ? iconArr[2].selecetd
              : iconArr[2].normal
          "
          alt=""
        />
        <p :class="['name', '/special' === this.$route.path ? 'checked' : '']">
          精选
        </p>
      </a>
    </li>
    <li>
      <a href="javascript:;" @click="change('/mine')">
        <img
          :src="
            '/mine' === this.$route.path
              ? iconArr[3].selecetd
              : iconArr[3].normal
          "
          alt=""
        />
        <p :class="['name', '/mine' === this.$route.path ? 'checked' : '']">
          我的
        </p>
      </a>
    </li>
  </ul>
</template>

<script>
export default {
  data() {
    return {
      iconArr: [
        {
          normal: require('@/assets/img/icon_game_default.png'),
          selecetd: require('@/assets/img/icon_game_selected.png')
        },
        {
          normal: require('../assets/img/icon_classify_default.png'),
          selecetd: require('../assets/img/icon_classify_selected.png')
        },
        {
          normal: require('../assets/img/icon_select_default.png'),
          selecetd: require('../assets/img/icon_select_selected.png')
        },
        {
          normal: require('../assets/img/icon_mine_default.png'),
          selecetd: require('../assets/img/icon_mine_selected.png')
        }
      ]
    }
  },
  methods: {
    change(url) {
      this.$router.replace(url)
    }
  }
}
</script>

<style scoped lang="less">
.wrap {
  width: 6.9rem;
  margin: 0 auto;
  position: relative;
}
.btm {
  height: 0.98rem;
}
.btmNav {
  display: flex;
  justify-content: space-around;
  width: 7.5rem;
  margin: 0 auto;
  position: fixed;
  background-color: #fff;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
  li {
    padding-top: 0.14rem;
    box-sizing: border-box;
    width: 25%;
    height: 0.98rem;
    font-size: 0.2rem;
    text-align: center;
    color: #9399a3;
    flex: 0 0 auto;
    img {
      width: 0.55rem;
      height: 0.5rem;
      margin: 0 auto;
    }
    .checked {
      color: #3b3f47;
      font-weight: 600;
    }
  }
}
</style>

在加载的时候使用数组去存图片路径 但是直接放字符串找不到图片,需要用require去加载!!!!!大坑

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值