css里的item.type引用不到 总是报错

来源:17-1 布局编写

慕运维2559375

2019-07-20

[Vue warn]: Error in render: "TypeError: Cannot read property 'name' of undefined"

<template>
  <div class="goods">
    <aside class="aside-menu">
      <ul>
        <li v-for="item in goods" class="menu-item">
          <span class="text">
            <span v-show="item.type>0" class="icon-item" v-bind:style="{background: iconMap[item.type].textColor }">
              {{iconMap[item.type].iconText}}
            </span>{{item.name}}
          </span>
        </li>
      </ul>
    </aside>
    <div class="foods-content">
    </div>
  </div>
</template>

<script>
  const ERR_OK = 0
export default {
  props:{
    seller:{
      type: Object
    }
  },
  data(){
    return {
      goods: {}
    }
  },
  created() {
    this.iconMap = [
      {
        iconText: '减',
        textColor: 'rgb(240,20,20)',
        name:'red'
      },
      {
        iconText: '折',
        textColor: '#EEC900',
        name:'yellow'
      },
      {
        iconText: '特',
        textColor: '#6495ED',
        name:'blue'
      },
      {
        iconText: '票',
        textColor: '#66CDAA',
        name:'green'
      },
      {
        iconText: '保',
        textColor: '#BF3EFF',
        name:'purple'
      }];
    this.$http.get('/api/goods').then((response) => {
      response = response.body
      if (response.errno === ERR_OK) {
        this.goods = response.data
      }
    })
  },
  name: 'goods'
}
</script>

<style>
  .goods{
    display: flex;
    position: absolute;
    top: 182px;
    bottom: 64px;
    width: 100%;
    overflow: hidden;
  }
  .aside-menu {
    flex: 0 0 80px;
    width: 80px;
    background: #f3f5f7;
  }
  .foods-content{
    flex: 1;
  }
  .menu-item{
    display: flex;
    justify-content: center;
    align-items: center;
    padding: auto 12px;
    height: 54px;
    position: relative;
  }
  .menu-item:not(:last-child)::after{
    content: '';
    position: absolute;
    height: 1px;
    width: 56px;
    padding: auto 12px;
    background: rgba(7,17,27,.1);
    bottom: 0;
  }
  .menu-item:first-child{
    color: rgb(240,20,20);
  }
  .icon-item{
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex: 0 0 14px;
  }
  .menu-item .text{
    font-size: 12px;
    /*display: flex;*/
    width: 56px;
    line-height: 14px;
  }
</style>
写回答

2回答

ustbhuangyi

2019-07-21

你在哪儿加的 v-if

0
5
ustbhuangyi
回复
慕运维2559375
类似吧
2019-07-22
共5条回复

慕运维2559375

提问者

2019-07-20

已经解决 v-show改为v-if 但是我想知道为什么 老师可以解答一下么

0
0

Vue.js2.5+cube-ui重构饿了么App(经典再升级)

掌握Vue1.0到2.0再到2.5最全版本应用与迭代,打造极致流畅的WebApp

9868 学习 · 4162 问题

查看课程